計算機科学のブログ

ほしい物リスト

Python - Getting Organized: Data Structure Choices - dictionary

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 6.(Getting Organized: Data Structure Choices)、SHARPEN YOUR PENCIL(40/78)の解答を求めてみる。

Jupyter(コード、入出力結果)

OrganizingData.ipynb

swimmers = []
for swim_file in swim_files:
    swimmers.append(swimclub.read_swim_data(swim_file)[0])
swimmers = {}
for file in swim_files:
    name = swimclub.read_swim_data(file)[0]
    swimmers[name] = []
swimmers
{'Hannah': [],
 'Darius': [],
 'Owen': [],
 'Mike': [],
 'Abi': [],
 'Ruth': [],
 'Tasmin': [],
 'Erika': [],
 'Maria': [],
 'Elba': [],
 'Ali': [],
 'Chris': [],
 'Aurora': [],
 'Katie': [],
 'Alison': [],
 'Emma': [],
 'Calvin': [],
 'Blake': [],
 'Bill': [],
 'Dave': [],
 'Lizzie': [],
 'Carl': []}