So I want to add the 3rd value of the elements in a list of lists if the first and second values are equal. And if not, I want the non-equal ones to be added to my sum list.
first=[[1,1,5],[2,3,7],[3,5,2],[4,4,6]]
second=[[1,1,3],[4,2,4],[2,3,2]]
sum=[]
for i in ((first)):
for j in ((second)):
if i[0]==j[0] and i[1]==j[1]:
sum.append([i[0],j[1],i[2]+j[2]])
print(sum)
so this gives me [[1, 1, 8], [2, 3, 9]] but I want [3,5,2],[4,4,6],[4,2,4] in my sum list too. How do I do this in python?