計算機科学のブログ

ほしい物リスト

Python - Lists of Numbers: Processing List Data - for loop 1

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 3.(Lists of Numbers: Processing List Data)、EXERCISE(67/101)の解答を求めてみる。

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

Average.ipynb

converts = []
for t in times:
    minutes, rest = t.split(':')
    seconds, hundredths = rest.split('.')
    converted_time = int(minutes) * 60 * 100 + int(seconds) * 100 + int(hundredths)
    converts.append(converted_time)
converts
[8795, 8107, 9096, 8322, 8795, 8830]