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?
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?
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.