我想将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
a
b
c
有没有更快的方法来合并这三个列表?这是我的代码:
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])
import itertools as it list(it.chain.from_iterable(it.izip(a,b,c)))