如何串联两个列表,以使元素处于替代位置? [英] How to concatenate two lists so that elements are in alternative position?
本文介绍了如何串联两个列表,以使元素处于替代位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:
a=[1,2,3,4,5,6]
b=[7,8,9,10,11,12]
然后结果:
c=[1,7,2,8,3,9,4,10,5,11,6,12]
如何连接两个列表,以使元素处于替代位置?
How do you concatenate two lists,so that the elements are in alternative positions??
我尝试将它们链接到新列表并重新排列,但没有成功. 如果您能告诉我很长的路要走(不用过多使用内置函数),那就太好了. 谢谢.
i have tried to link them in to a new list and rearrange but its not coming. it would be nice if you could tell me the long way(without using built in functions too much).I m new to python and not much is taught in my school. Thank you.
推荐答案
只需在它们的长度相同的情况下为它们附加一个for循环即可:
Just append them with a for loop, assuming they're the same length:
c = []
for i in range(len(a)):
c.append(a[i])
c.append(b[i])
这篇关于如何串联两个列表,以使元素处于替代位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文