Trying to think of a one-liner to achieve the following ( summing all the values of a key) :
>>> data = [(\'a\',1),(\'b\',3),(\'a\',4),(\'c\',9),(\'
Use reduce and collections.Counter:
>>> from operator import add >>> from collections import Counter >>> reduce(add, (Counter(dict([x])) for x in data)) Counter({'c': 9, 'a': 5, 'b': 4, 'd': 3})