Element-wise addition of 2 lists?

后端 未结 16 1209
感动是毒
感动是毒 2020-11-22 07:48

I have now:

list1 = [1, 2, 3]
list2 = [4, 5, 6]

I wish to have:

[1, 2, 3]
 +  +  +         


        
16条回答
  •  花落未央
    2020-11-22 08:49

    Use map with lambda function:

    >>> map(lambda x, y: x + y, list1, list2)
    [5, 7, 9]
    

提交回复
热议问题