python - Save line in file to list -
file = input('name: ') open(file) infile: line in infile: name in infile: name print(name[line])
so if user pass file of vertical list of sentences, how save each sentence own list?
sample input:
'hi' 'hello' 'cat' 'dog'
output:
['hi'] ['hello'] , on...
>>> [line.split() line in open('file.txt')] [['hi'], ['hello'], ['cat'], ['dog']]
or, if want more careful making sure file closed:
>>> open('file.txt') f: ... [line.split() line in f] ... [['hi'], ['hello'], ['cat'], ['dog']]
Comments
Post a Comment