Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 11(Storing Data Using Other Collection Types)、11.8(Exercises) 9.を解いてみる。
11.8(Exercises) 9.
コード(BBEdit)
sample9.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def dbHeadings(db): result = set() for value in db.values(): result.update(value.keys()) return result if __name__ == '__main__': db = { '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'] } } print(dbHeadings(db))
入出力結果(Terminal, IPython)
$ ./sample9.py {'born', 'author', 'forename', 'notes', 'surname', 'died' $
0 コメント:
コメントを投稿