Reputation: 57
with open('filename') as f:
list1 = f.read().splitlines()
print list1
This gives me a comma-separated list with each line from the file like this: ['line1', 'line2', 'line3',...]
I now want to separate each line into it's own array like so: [ [line1], [line2], [line3]...] -How can I do this?
Upvotes: 0
Views: 113
Reputation: 118001
You can create a list
within a list comprehension
with open('filename') as f:
list1 = [[i] for i in f.read().splitlines()]
print list1
Upvotes: 2