Home > Back-end >  Python sum two list in a list
Python sum two list in a list

Time:11-14

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]]

CodePudding user response:

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

  • Related