if you do not care about the order of the elements, then you can use the Karls method.
otherwise use a sorted dict:
import collections
data = [(123, 9), (111, 5), (12, 1), (123, 4), (12, 4),
(109, 5), (12, 4), (35, 7), (111, 4), (124, 6)]
order = collections.OrderedDict()
for value, count in data:
order[value] = order.setdefault(value, 0) + count
defaultdict, , , :
import collections
default = collections.defaultdict(int)
for value, count in data:
default[value] += count
.