Reputation: 2571
I have a file such that each line consists of two strings separated by variable space, like below:
"Doe, Mary" "W 135"
How can this be parsed into pairs of strings, ["Doe, Mary", "W 135"]
?
Upvotes: 1
Views: 132
Reputation: 365707
with open('file.txt') as f:
pairs = csv.reader(f, delimiter=' ', skipinitialspace=True)
Now you can make a list of pairs
, iterate over it in a for loop, whatever.
Upvotes: 2