我想同时遍历两个列表,同时还能够增加一个变量:我能够实现这一点,但是要手动增加行数。
for name, time in zip(Linklist, Timelist):
worksheet.write(row, col, name)
worksheet.write(row, col + 1, time)
row=row+1
尝试查看是否可以执行以下操作:
for row, name, time in zip(Linklist, Timelist):
worksheet.write(row, col, name)
worksheet.write(row, col + 1, time)
答案 0 :(得分:3)
只需使用enumerate
并嵌套拆包:
for row, (name, time) in enumerate(zip(Linklist, Timelist)):
答案 1 :(得分:1)
for row, name, time in zip(itertools.count(), Linklist, Timelist):
...