開発環境
- OS X Mavericks - Apple(OS)
 - Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
 - Python (プログラミング言語)
 
初めてのコンピュータサイエンス(Jennifer Campbell、Paul Gries、Jason Montojo、Greg Wilson(著)長尾 高弘(翻訳))の9章(集合と辞書)、9.5(練習問題)、11.を解いてみる。
9.5(練習問題)、11.
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-
def dbHeadings(db):
    result = set()
    for k in db:
        result |= set(db[k].keys())
    return result
scientists = {
    'Jグドール': {
        '姓': 'ゴドール',
        '名': 'ジェーン',
        '生年': 1934,
        '没年': None,
        '注目': '霊長類研究者',
        '著作': ['In the Shadow of Man', 'The Chimpanzees of Gombe']
    },
    'Rフランクリン': {
        '姓': 'フランクリン',
        '名': 'ロザリンド',
        '生年': 1920,
        '没年': 1957,
        '注目': 'DNAの発見に貢献'
    },
    'Rカーソン': {
        '姓': 'カーソン',
        '名': 'レイチェル',
        '生年': 1907,
        '没年': 1964,
        '注目': 'DDTの毒外に注意を喚起',
        '著作': ['沈黙の春']
    }
}
print('database: {0}'.format(scientists))
print('database headings: {0}'.format(dbHeadings(scientists)))
入出力結果(Terminal)
$ ./sample.py
database: {'Jグドール': {'名': 'ジェーン', '生年': 1934, '著作': ['In the Shadow of Man', 'The Chimpanzees of Gombe'], '姓': 'ゴドール', '注目': '霊長類研究者', '没年': None}, 'Rフランクリン': {'姓': 'フランクリン', '名': 'ロザリンド', '生年': 1920, '注目': 'DNAの発見に貢献', '没年': 1957}, 'Rカーソン': {'名': 'レイチェル', '生年': 1907, '著作': ['沈黙の春'], '姓': 'カーソン', '注目': 'DDTの毒外に注意を喚起', '没年': 1964}}
database headings: {'名', '生年', '著作', '姓', '注目', '没年'}
$
						
0 コメント:
コメントを投稿