python - 将两个列表的项目合并到也包含索引的元组列表中

标签 python list tuples

实现以下目标的最 pythonic 方式是什么:

list_a = ["A", "B", "C"]
list_b = ["X", "Y", "Z"]

idx_start = 100

result = [ (100, "A", "X"), (101, "B", "Y"), (102, "C", "Z") ]

保证列表的大小相同。

最佳答案

from itertools import count
zip(count(idx_start), list_a, list_b)

关于python - 将两个列表的项目合并到也包含索引的元组列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29035143/

相关文章:

python - 使用 pycountry 和 gettext 将翻译后的国家名称转换为 alpha2

python - 使用 Pandas 计算滚动窗口中的不同字符串

python - 从列表的每个列表中创建索引为 i 的新元组

python - 处理一组独特的元组

python - Buildozer 如何解决 "--ndk-api=21"错误

python - scrapy - python 问题

c# - Linq 计算列表中的唯一值

string - 从字符串列表中查找公共(public)子字符串

python 错误: tuples indices must be integers or slices not tuples

c++ - 如何有效地实现 std::tuple 使得空类型的元组本身就是空类型?