我有3个列表:
a = [0, 1, 2]
b = [3, 4, 5]
c = [6, 7, 8]
我需要从中创建一个元组列表。
输出应如下所示:
[(0, 3, 6), (1, 4, 7), (2, 5, 8)]
答案 0 :(得分:3)
仅使用zip
。
a = [0, 1, 2]
b = [3, 4, 5]
c = [6, 7, 8]
zipped = list(zip(a, b, c))
答案 1 :(得分:2)
尝试一下
>>> a,b,c =[0, 1, 2],[3, 4, 5],[6, 7, 8]
>>> [(i,j,k) for i,j,k in zip(a,b,c)]
[(0, 3, 6), (1, 4, 7), (2, 5, 8)]
答案 2 :(得分:1)
您可以这样做:
list(zip(a, b, c))