I have a nested list in python, i=[[1,2,3],[4,5,6]]. I want to sum the terms such that the final result is j=[1+4,2+5,6+3]. I have tried:
i=[[1,2,3],[4,5,6]]
j=[sum(x) for x in zip(i)]
But this is what I get instead:
>>>print j
[6, 15]
I have a nested list in python, i=[[1,2,3],[4,5,6]]. I want to sum the terms such that the final result is j=[1+4,2+5,6+3]. I have tried:
i=[[1,2,3],[4,5,6]]
j=[sum(x) for x in zip(i)]
But this is what I get instead:
>>>print j
[6, 15]