gpt4 book ai didi

python - 将 3 个列表合并为 1 个列表

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

<分区>

我想将 3 个列表合并为一个列表。例如,我有三个列表:

a = [0, 3, 6, 9]
b = [1, 4, 7, 10]
c = [2, 5, 8, 11]

最后我想得到

merged = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]

a, b, c

有没有更快的方法来合并这 3 个列表?这是我的代码:

merged = []
a = [0, 3, 6, 9]
b = [1, 4, 7, 10]
c = [2, 5, 8, 11]
for i in range(0, len(a)):
merged.append(a[i])
merged.append(b[i])
merged.append(c[i])

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