Reputation: 99
I'm trying to use the CSV module to put the contents of a CSV file into a list and then sort the list accordingly. The problem is that when I read the list it puts each column in its own list separated by a comma and a '\n'.
with open(filename) as file:
csv_file = file.readlines()
print(csv_file)
yields:
['6,3,16,3\n', '11,7,7\n', '17,10,14\n', '8,5,19\n']
And any other way I've tried to put them into a list only yields me:
[[6, 3, 16, 3], [11, 7, 7], [17, 10, 14], [8, 5, 19]]
I just need one single editable list to work from but I can't get it to work in the way I'm wanting, and I'm not sure what I'm doing wrong. This is my first time working with CSV.
Upvotes: 0
Views: 37
Reputation: 26
Upvotes: 1