Here's my list of tuples:
regions = [(23.4, 12, 12341234),
(342.23, 19, 12341234),
(4312.3, 12, 12551234),
(234.2, 12, 12341234)]
I'm trying to sum the first index value in a list of tuples where the values at indices 1 and 2 are identical. Note that regions[0] and regions[3] have the same values at indices 1 and 2.
My desired list is:
result = [(257.6, 12, 12341234),
(342.23, 19, 12341234),
(4312.3, 12, 12551234)]
I realize that I probably need to save it as a dictionary first, probably with the second value as the first key and the third value as the second key and summing if it already exists. Just wondering if there's a better or easier way: I'm thinking maybe using some intersect function.