【发布时间】:2017-11-03 17:33:21
【问题描述】:
我可以像这样组合列表的每两个元素:
colors=['green','yellow','red','green','yellow','red']
colors2=[x+y for x,y in zip(colors[0::2],colors[1::2])]
colors2
Out: ['greenyellow','redgreen','yellowed']
但是,我无法组合列表的每三个元素:
colors3=
[x+y+z for x,y,z in zip(colors[0::3],colors[1::4],colors[2::5])]
colors3
Out: ['greenyellowred']
我的切片未对齐的其他三个在哪里?
【问题讨论】:
标签: python zip list-comprehension slice