計算機科学のブログ

ほしい物リスト

Python - Diving in: Let's Make a Splash - string, methods, strip, split

Head First Python: A Learner’s Guide to the Fundamentals of Python Programming, A Brain-Friendly GuidePaul Barry(著)、 O’Reilly Mediaの Chapter 2.(Diving in: Let’s Make a Splash)、SHARPEN YOUR PENCIL(167/682)の解答を求めてみる。

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

Darius.ipynb

import os


FILENAME = 'Darius-13-100m-Fly.txt'
FOLDER = "swimdata"
with open(os.path.join(FOLDER, FILENAME)) as f:
    lines = f.readlines()
lines
['1:27.95,1:21.07,1:30.96,1:23.22,1:27.95,1:28.30\n']
times = lines[0].strip().split(',')
times
['1:27.95', '1:21.07', '1:30.96', '1:23.22', '1:27.95', '1:28.30']