[Solved] Adding the sorted elements in list
You can do that as follows: from collections import defaultdict a = [(1,22),(1,22),(2,29),(2,16),(3,56),(4,32),(4,12)] b = defaultdict(lambda: 0) for i,j in a: b[i] += j >>> print b {1:44, 2:45, 3:56, 4:44} DEMO 4 solved Adding the sorted elements in list