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) 3.を解いてみる。
11.8(Exercises) 3.
コード(BBEdit)
sample3.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def getAllAuthorNames(filenames): names = set() for filename in filenames: with open(filename) as f: for line in f: if line.lower().startswith('author'): names.add(line[6:].strip()) return names if __name__ == '__main__': import glob filenames = glob.glob('*.ent') print(getAllAuthorNames(filenames))
入出力結果(Terminal, IPython)
$ ./sample3.py {'C.XU,W.TEMPEL,K.LIU,J.R.WALKER,C.BOUNTRA,C.H.ARROWSMITH,A.M.EDWARDS,', 'X.JI,C.TANG,Q.ZHAO,W.WANG,Y.XIONG', 'D.W.TOH,L.SUN,J.TAN,Y.CHEN,L.Z.M.LAU,W.HONG,E.C.Y.WOON,Y.G.GAO', '2 J.MIN,STRUCTURAL GENOMICS CONSORTIUM (SGC)' $
0 コメント:
コメントを投稿