Python - gazpacho - Working with Data: Data Manipulation - json
Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly Guide、 Paul Barry(著)、 O’Reilly Mediaの Chapter 10.(Working with Data: Data Manipulation)、EXERCISE(475/682)の解答を求めてみる。
Jupyter(コード、入出力結果)
webapp/TestStandalone.ipynb
import json
with open('records.json') as f:
records = json.load(f)
from swimclub import event_lookup
times = []
COURSES = ('LC Men', 'LC Women', 'SC Men', 'SC Women')
for course in COURSES:
times.append(records[course][event_lookup('Darius-13-100m-Fly.txt')])
times
['49.45', '55.48', '47.78', '54.05']
average = 10
footer = f"""
<p>Average time: {average}</p>
<p>
M: {times[0]} ({times[2]})<br>
W: {times[1]} ({times[3]})
</p>
</body>
"""
print(footer)
<p>Average time: 10</p>
<p>
M: 49.45 (47.78)<br>
W: 55.48 (54.05)
</p>
</body>