Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media; )
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media; )のChapter 5(hashes and databases - Putting data in its place)、Sharpen your pencil(p.147)を解いてみる。
Sharpen your pencil(p.147)
コード(BBEdit)
sample147,.py
#!/usr/bin/env python3
#-*- coding: utf-8
scores = []
names = []
with open('results.txt') as result_f:
for line in result_f:
name, score = line.split()
scores.append(float(score))
names.append(name)
scores.sort(reverse=True)
print(scores)
print(names)
入出力結果(Terminal)
$ ./sample147.py [9.12, 8.65, 8.45, 8.31, 8.05, 7.81, 7.21] ['Johnny', 'Juan', 'Joseph', 'Stacey', 'Aideen', 'Zack', 'Aaron'] $
0 コメント:
コメントを投稿