How can I add the corresponding elements of several lists of numbers?

前端 未结 6 1847
暖寄归人
暖寄归人 2020-12-03 07:38

I have some lists of numbers:

[1, 2, 3, 4, 5]
[2, 3, 4, 5, 6]
[3, 4, 5, 6, 7]

How can I add these lists\' elements, assuming that all of th

6条回答
  •  独厮守ぢ
    2020-12-03 08:33

    >>> lis=[[1,2,3,4,5],[2,3,4,5,6],[3,4,5,6,7]]
    
    >>> [sum(x) for x in zip(*lis)]
    [6, 9, 12, 15, 18]
    

提交回复
热议问题