I have a string containing CSV content. I turned it into a list like so:
from StringIO import StringIO
import csv
f = StringIO(list_csv)
my_list = csv.reader(f, delimiter=',')
Now I want to loop twice over the list, but the second time I try to loop, the code goes through as if the list was empty:
for item in my_list:
code = item[1]
print "code: "+code
for item in my_list:
desc = item[2]
print "desc: "+desc
(this code is simplified for demonstration purposes, I can't combine execution in a single loop)
I figured the list is still attached to the StringIO, and when it's done looping it's done reading, so it won't read again. Is there a one-liner to transform that into a regular list in the memory, that I could loop several times? I feel like running a loop manually copying values is reinventing the wheel.... but I can do that if there's no other option. Just asking for something less lengthy code-wise. Thanks!
new_list = list(my_list)and loop overnew_list