I have a huge list of sublists, each sublist consisting of a tuple and a list of 4 integers.
I want to create a list of unique tuples that adds each integer values of the list (keeping the four integers in the list separate).
Short Example:
[[(30, 40), [4, 7, 7, 1]],[(30, 40), [2, 9, 3, 4]],[(30, 40), [6, 5, 10, 0]],[(20, 40), [4, 0, 4, 0]],[(20, 40), [3, 4, 14, 5]],[(20, 40), [3, 2, 12, 0]],[(10, 40), [223, 22, 12, 9]]]
Output wanted:
[[(30, 40), [12, 21, 20, 5]],[(20, 40), [2, 9, 3, 4]],[(10, 40), [223, 22, 12, 9]]
I have tried using a dictionary
l = [[(30, 40), [4, 7, 7, 1]],[(30, 40), [2, 9, 3, 4]],[(30, 40), [6, 5, 10, 0]],[(20, 40), [4, 0, 4, 0]],[(20, 40), [3, 4, 14, 5]],[(20, 40), [3, 2, 12, 0]],[(10, 40), [223, 22, 12, 9]]]
dict_tuples = {}
for item in l:
if item[0] in dict_tuples:
dict_tuples[item[0]] += item[1]
else:
dict_tuples[item[0]] = item[1]
But here I am just getting a long list of integer values for each tuple. I want to sum of each index in the list of four integers.