如何通过交替两个不相等列表的值来创建新列表? [英] How do I create a new list by alternating the values of two unequal lists?

查看:54
本文介绍了如何通过交替两个不相等列表的值来创建新列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我假装有两个长度不相等的列表,并希望将它们列入新列表。

例如:

list1 = [a,A, aa,aaa]和list2 = [b,B] make list3 = [a,b,A,B,aa,aaa]



我可以使用insert(索引) ,item)为此?

我不想在其中使用带有'zip'的任何方法。

I pretend there are two lists that are unequal in length and want to make them into a new list.
For example:
list1 = [a,A,aa,aaa] and list2 = [b, B] make list3 = [a,b,A,B,aa,aaa]

Can I use insert(index, item) for this?
I don't want to use any methods with 'zip' in it.

推荐答案

list1.union (list2)给出一个包含lis1和list2的所有元素的列表
list1.union(list2) gives a list that contains all the elements of lis1 and list2


是的,你可以。请参阅此 turoial [ ^ ]。

但是如果元素的位置无关紧要,那么你可以这样做:

Yes, you can. Refer this turoial[^].
But if position of the elements doesn't matter, then you can go something like this:
newList = list1 + list2; 
#or
list1 += list2

< br $> b $ b

-KR



-KR


这篇关于如何通过交替两个不相等列表的值来创建新列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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