如何在python中把两个列表的各项分别合并为列表
展开全部
用extend():
Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> A = [1, 2, 3]
>>> B = [4, 5, 6]
>>> A1 = A[:]
>>> A.append( B )
>>> print( A )
[1, 2, 3, [4, 5, 6]]
>>> A = A1[:]
>>> print( A )
[1, 2, 3]
>>> A += B
>>> print( A )
[1, 2, 3, 4, 5, 6]
>>>
Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> A = [1, 2, 3]
>>> B = [4, 5, 6]
>>> A1 = A[:]
>>> A.append( B )
>>> print( A )
[1, 2, 3, [4, 5, 6]]
>>> A = A1[:]
>>> print( A )
[1, 2, 3]
>>> A += B
>>> print( A )
[1, 2, 3, 4, 5, 6]
>>>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
[ [a,b] for a,b in zip(list1,list2)]
生成一个以列表list1,list2各项合并列表为元素的列表
生成一个以列表list1,list2各项合并列表为元素的列表
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是加起来生成一个列表吗
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询