I'm struggling with writing a dictionary of lists to a .csv file.
This is how my dictionary looks like:
dict[key1]=[1,2,3]
dict[key2]=[4,5,6]
dict[key3]=[7,8,9]
I want the .csv file to look like:
key1 key2 key3
1 4 7
2 5 8
3 6 9
At first I write the header:
outputfile = open (file.csv,'wb')
writefile = csv.writer (outputfile)
writefile.writerow(dict.keys())
So far so good... However, my problem is that I don't know how I could assign one list to the corresponding column. e.g.:
for i in range(0,len(dict[key1])):
writefile.writerow([dict[key1][i],dict[key2][i],dict[key3][i])
will randomly fill the columns. Another problem is, that I have to manually fill in the keys and can't use it for another dictionary with 4 keys.