Writing Python lists to columns in csv

csv, list, python

Solution

Change them to rows:

rows = zip(list1, list2, list3, list4, list5)

Then just:

import csv

with open(newfilePath, "w") as f:
    writer = csv.writer(f)
    for row in rows:
        writer.writerow(row)

Problem

I have 5 lists, all of the same length, and I'd like to write them to 5 columns in a CSV. So far, I can only write one to a column with this code: ``` with open('test.csv', 'wb') as f: writer = csv.writer(f) for val in test_list: writer.writerow([val]) ``` If I add another `for` loop, it just writes that list to the same column. Anyone know a good way to get five separate columns?

Original source