Python以交替方式合并两个长度不等的列表 [英] Python combine two lists of unequal length in alternating fashion

查看:305
本文介绍了Python以交替方式合并两个长度不等的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个列表,我想以一种交替的方式将它们组合起来,直到一个列表用完,然后我要继续从较长的列表中添加元素.

I have a two lists, and I want to combine them in an alternating fashion, until one runs out, and then I want to keep adding elements from the longer list.

再来一次.

list1 = [a,b,c]

list2 = [v,w,x,y,z]

result = [a,v,b,w,c,x,y,z]

类似于此问题( Pythonic组合方式两个列表以交替的方式进行?),不同的是,在第一个列表用完后,列表停止合并:(.

Similar to this question (Pythonic way to combine two lists in an alternating fashion?), except in these the lists stop combining after the first list has run out :(.

推荐答案

以下是出色的 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆