Pythonistic way to intersect and add elements of lists at the same time
I have 3 lists, a , b and c Each of this lists contains tuples with 3 numbers. Here is an example input: a = [(1,2,4),(1,7,8),(1,5,4),(3,6,7)] b = [(1,2,5),(1,9,3),(1,0,3),(3,6,8)] c = [(2,6,3),(2,4,9),(2,8,5),(1,2,7)] I'm looking for a way to generate a list that takes elements of those 3 lists if the two firsts items of eachs tuple are equals, and addind the third element. In the data I gave, there is only 1 set of tuple with the 2 first values equals : (1,2,4) , (1,2,5) and (1,2,7) . If I add their third value I have 4+5+7 = 16 , so with those data, I should have [(1,2,16)] in the end. The