開発環境
- Mac OS X Snow Leopard (OS)
- WingIDE
- Script言語: Python
『初めてのコンピュータサイエンス』(Jennifer Campbell, Paul Gries, Jason Montojo, Greg Wilson 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-463-7)の9章(集合と辞書), 9.5(練習問題), 11を解いてみる。
11.
コード
def db_headings(d):
result=set()
for k in d:
result=result | set(d[k].keys())
return result
d={
'jgoodall' : {'surname' : 'Goodall',
'forename' : 'Jane',
'born' : 1934,
'died' : None,
'notes' : 'primate researcher',
'author' : ['In the Shadow of Man', 'The Chimpanzees of Gombe']},
'rfranklin' : {'surname' : 'Franklin',
'forename' : 'Rosalind',
'born' : 1920,
'died' : 1957,
'notes' : 'contributed to discovery of DNA'},
'rcarson' : {'surname' : 'Carson',
'forename' : 'Rachel',
'born' : 1907,
'died' : 1964,
'notes' : 'raised awareness of effects of DDT',
'author' : ['Silent Spring']}
}
入出力結果(Python Shell)
サンプルファイルに「,」が抜けてることに気づくまで少し時間がかかった。。
0 コメント:
コメントを投稿