-1

My problem statement is I have a 2d list as x = [[1,2,3], [4,5,6]]

I want the out put as [5,7,9]

can somebody help me how can i achieve it?

  • 2
    Possible duplicate of [Add SUM of values of two LISTS into new LIST](https://stackoverflow.com/questions/14050824/add-sum-of-values-of-two-lists-into-new-list) – DavidG Oct 18 '17 at 09:01

1 Answers1

1

This will do it:

[sum(p) for p in zip(*x)]

This produces:

[5, 7, 9]

Note that this will also work if x has more than two sub-lists.

Tom Karzes
  • 22,815
  • 2
  • 22
  • 41