所以我有三个清单:
['this', 'is', 'the', 'first', 'list']
[1, 2, 3, 4, 5]
[0.01, 0.2, 0.3, 0.04, 0.05]
是否有方法允许我按索引顺序打印这些列表中的值?
例如
this, 1, 0.01 (all items at list[0])
is, 2, 0.2 (all items at list[1])
the, 3, 0.3 (all items at list[2])
first, 4, 0.04 (all items at list[3])
list, 5, 0.05 (all items at list[4])
每次运行脚本时,每个列表中的项目数都会有所不同,但它们最终的值总是相同的。因此,一次,脚本可以创建三个包含30个项的数组,另一次,它只能在每个数组中创建15个值,等等
使用
zip
items
将是一个元组,按顺序从每个列表中都有一个值。将列表拉到一起,并在最短的列表用完项目时停止。
你可能要找的是
zip
:相关问题 更多 >
编程相关推荐