Adam Smith
Adam Smith

Reputation: 15

Python sum two list in a list

can someone help me sum this two list. so first would be 10+1=11 then 20+2=22 then 30+3=33 and so on:

list1 = [[1,2],[3,4],[5,6]]
list2 = [[10,20],[30,40],[50,60]]

the output would be something like this:

list3[[11,22],[33,44],[55,66]]

Upvotes: 0

Views: 47

Answers (1)

lbarqueira
lbarqueira

Reputation: 1305

here is a possible solution:

list1 = [[1,2],[3,4],[5,6]]
list2 = [[10,20],[30,40],[50,60]]


def sum(list1, list2):
    new_list=[]
    for i in range(len(list1)):
        new_list.append([list1[i][j]+list2[i][j] for j in range(len(list1[i]))])
    return new_list  

print(sum(list1,list2))

[[11, 22], [33, 44], [55, 66]] Thanks, and good python

Upvotes: 1

Related Questions