Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
以下のように、各行が可変スペースで区切られた2つの文字列で構成されるようなファイルがあります。
"Doe, Mary" "W 135"
これを文字列のペアにどのように解析できます["Doe, Mary", "W 135"]か?
["Doe, Mary", "W 135"]
with open('file.txt') as f: pairs = csv.reader(f, delimiter=' ', skipinitialspace=True)
のリストを作成pairsしたり、for ループで繰り返し処理したりできます。
pairs