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

前端 未结 6 1870
暖寄归人
暖寄归人 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:25

    Assuming:

    a = [1,2,3,4,5]
    b = [2,3,4,5,6]
    c = [3,4,5,6,7]
    

    just do this:

    [sum(n) for n in zip(*[a, b, c])]
    

提交回复
热议问题