gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:47:12 26 4
gpt4 key购买 nike

实现以下目标的最 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com