我有以下列表:
a = ["1 Monday","1 Wednesday","1 Friday"]
b = ["2 Tuesday","2 Thursday","2 Saturday"]
我想把这些结合起来:
c = ["1 Monday", "2 Tuesday", "1 Wednesday", "2 Thursday", "1 Friday", "2 Saturday"]
我想一个接一个地做这个。所以附加a的第一个元素和b的第一个元件,然后附加a的第二个元件和b的第二元件等等。
您可以将itertools
与zip
:一起使用
In [3585]: import itertools
In [3586]: list(itertools.chain(*zip(a,b)))
Out[3586]:
['1 Monday',
'2 Tuesday',
'1 Wednesday',
'2 Thursday',
'1 Friday',
'2 Saturday']
基本解决方案
list_turn = []
a = ["1 Monday","1 Wednesday","1 Friday"]
b = ["2 Tuesday","2 Thursday","2 Saturday"]
for i in range(len(a)):
list_turn.append(a[i])
list_turn.append(b[i])