python - 在 Python 中,我可以按索引号顺序打印 3 个列表吗?

标签 python list

所以我有三个列表:

['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:

>>> x = ['this', 'is', 'the', 'first', 'list']
>>> y = [1, 2, 3, 4, 5]
>>> z = [0.01, 0.2, 0.3, 0.04, 0.05]
>>> zip(x,y,z)
[('this', 1, 0.01), ('is', 2, 0.20000000000000001), ('the', 3, 0.29999999999999999), ('first', 4, 0.040000000000000001), ('list', 5, 0.050000000000000003)]
>>> for (a,b,c) in zip(x,y,z):
...     print a, b, c
... 
this 1 0.01
is 2 0.2
the 3 0.3
first 4 0.04
list 5 0.05

关于python - 在 Python 中,我可以按索引号顺序打印 3 个列表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1615289/

相关文章:

python - django:自动检测数据库上所做的 CRUD 更改

python - 根据字典的值将字典转换为字典列表

python - list.index() 是否实现缓存

python - 构建游戏,需要有关库存的建议

python - 命名元组的字段中可以包含哪些数据类型?

python - 使用带有特征矩阵的 scikit_learn 的奇怪卡方结果

python - 使同步 Flask 异步 - Flask 实例

c# - ASP.NET C# 列出哪个和什么时候?

Python - 从临时文件中写入和读取

Python RegEx 捕获模式后的第一个词