zip_longest(* d,fill values ='0')不适用于所有大小的d

时间:2019-03-20 05:53:25

标签: python multidimensional-array itertools

因此,我正在使用zip_longest在同一文件上写入具有不同大小的列。我这样使用:

import csv
from itertools import zip_longest
d = event_time
export_data = zip_longest(*d, fillvalue = '0')
with open(filenameOut, 'w', encoding="ISO-8859-1", newline='') as Output:
    wr = csv.writer(Output, delimiter=' ')
    wr.writerows(export_data)
Output.close()

event_time是N个元素的列表,其中哪个元素是大小未知的另一个列表。

问题是zip_longest不适用于所有N值。

如果N = 10,它可以工作,并且在我的输出文件中,我在最后几行得到如下内容: (九个零和一个不同的数字)

0 0 0 0 0 99916 0 0 0 0
0 0 0 0 0 99918 0 0 0 0
0 0 0 0 0 99922 0 0 0 0
0 0 0 0 0 99924 0 0 0 0
0 0 0 0 0 99932 0 0 0 0
0 0 0 0 0 99998 0 0 0 0

但是,如果N = 100,我应该得到类似的东西,但是有99个零,相反,最后我得到一列零。

0 个答案:

没有答案