開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Python (Paul Barry(著)、 O'Reilly Media )のChapter 11(Dealing with Complexity: Data wrangling)、SHARPEN YOUR PENCIL(p.411)を解いてみる。
SHARPEN YOUR PENCIL(p.411)
コード(BBEdit, Emacs)
sample411.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- row_data = {} with open('PaceData.csv') as paces: column_headings = paces.readline().strip().split(',') column_headings.pop(0) for each_line in paces: row = each_line.strip().split(',') row_label = row.pop(0) inner_dict = {} for i in range(len(column_headings)): inner_dict[row[i]] = column_headings[i] row_data[row_label] = inner_dict times = [] for t in row_data['Marathon'].keys(): times.append(t) headings = [] for h in sorted(row_data['10mi'].values(), reverse=True): headings.append(h) time = [] for t in row_data['20k'].keys(): if row_data['20k'][t] == '79.3': time.append(t) print(times, headings, time, sep='\n')
入出力結果(Terminal, IPython)
$ ./sample411.py ['2:36:52', '2:30:02', '4:52:30', '2:20:21', '3:34:12', '2:47:42', '2:55:20', '2:26:44', '3:24:53', '4:10:18', '2:23:31', '4:39:46', '3:43:57', '2:11:17', '2:59:16', '3:39:01', '2:51:28', '4:46:04', '3:07:26', '2:17:16', '5:05:48', '4:21:42', '3:11:39', '5:41:48', '3:15:58', '4:04:48', '5:34:16', '4:33:36', '2:08:24', '2:05:34', '2:14:15', '3:20:22', '6:13:37', '2:44:00', '3:59:25', '5:19:43', '5:12:41', '3:48:59', '2:40:24', '5:57:21', '2:33:25', '4:27:35', '5:49:29', '4:59:05', '4:15:56', '3:29:29', '3:54:09', '3:03:18', '5:26:55', '6:05:23'] ['84.8', '82.9', '81.1', '79.3', '77.5', '75.8', '74.2', '72.5', '70.9', '69.4', '67.9', '66.4', '64.9', '63.5', '62.1', '60.7', '59.4', '58.1', '56.8', '55.5', '54.3', '53.1', '52', '50.8', '49.7', '48.6', '47.5', '46.5', '45.5', '44.5', '43.5', '42.5', '41.6', '40.7', '39.8', '38.9', '38', '37.2', '36.4', '35.6', '34.8', '34', '33.3', '32.6', '31.8', '31.1', '30.5', '29.8', '29.1', '28.5'] ['1:00:23'] $
0 コメント:
コメントを投稿