2014年6月8日日曜日

開発環境

Head First Python (Paul Barry(著)、 O'Reilly Media )のChapter 5(Comprehending data: Work that data)、SHARPEN YOUR PENCIL(p.145)を解いてみる。

SHARPEN YOUR PENCIL(p.145)

コード(BBEdit)

sample145.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

with open('james.txt') as f_james, open('sarah.txt') as f_sarah, \
     open('julie.txt') as f_julie, open('mikey.txt') as f_mikey:
    james = f_james.readline().strip().split(',')
    sarah = f_sarah.readline().strip().split(',')
    julie = f_julie.readline().strip().split(',')
    mikey = f_mikey.readline().strip().split(',')


print(sorted(james))
print(sorted(sarah))
print(sorted(james))
print(sorted(mikey))

入出力結果(Terminal)

$ ./sample145.py
['2-22', '2-34', '2.34', '2.45', '2:01', '2:01', '3.01', '3:10', '3:21']
['2-25', '2-55', '2.18', '2.58', '2:39', '2:54', '2:55', '2:55', '2:58']
['2-22', '2-34', '2.34', '2.45', '2:01', '2:01', '3.01', '3:10', '3:21']
['2.49', '2:22', '2:38', '3.01', '3.02', '3.02', '3:01', '3:02', '3:22']
$

0 コメント:

コメントを投稿