- Where Developers Learn, Share, & Build Careers


I am trying to export data to CSV, where the data contains two lists of unequal items Length

  import csv item_dictionary = {'13742': 'cat', '25037': 'dog'} name = item_dictionary.values ​​() data = [[1, 2, 3] , 4, 5, 6], [7, 8, 9, 10]] export_data = zip (* data) myfile = open ('sample.csv', 'wb') wr = csv.writer (myfile) wr.writerow (Names) Wr.writerows (export_data) myfile.close ()   

This gives me this output, which includes 5 and 6 in data [0] Is not done. >

  dog cat 1 7 2 8 3 9 4 10   

What I should do is:

  dog To include all values ​​of cat 1 7 2  data [0] , how can I modify my code to not be limited to the  length   

data [1]

In fact, ZIP prevents it to reach the end of the least movable. This is a function to use when you want to zip at the end of the long runner. itertools export_data = itertools.izip_longest (* data, fillvalue = '')

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -