Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

want to read rows from a csv file and turn them into lists my code >> list 0 = [] list 1 = [] list 2 = [] list 3 = [] list 4 = [] list 5 = [] with open('all_plans2.csv', 'rb') as csvfile: myreader = csv.reader(csvfile) # for row in myreader: # print ', '.join(row) count = 0 for row in myreader: print count count += 1 listcount =rowcount this prints 0 1 2 3 4 5 so I have 6 rows in the csv that I would like to manipulate as 6 lists:(list0, list1, ...)

Lists & Dictionaries
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

What happens if you print row?
The first lines list 0 =[] produce errors when I try them. The import csv is missing. The listcount=rowcount row gives an error because they are not used at all other than that line. The program above if all were working would print exactly what you ask it to, the integer variable count. Since there are 6 rows it would print the integers fro 0 to 6 not including 6. Below is an example that uses a list of list and a dictionary of lists. Which would be easier and much better than using separate list variables, and will work with any number of lines without adding more variables. import csv # initialize list rows1 = [] # initialize dictionary rows2 = {} with open('f:/test.csv', 'rb') as csvfile: myreader = csv.reader(csvfile) count = 0 for row in myreader: # add row as list to list rows1.append(row) # add row as list to dictionary rows2[count] = row count += 1 print rows1 print print rows2
Thank you, that's what i needed. I appreciate you taking the time to help me.

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question