I have a list of (label, count) tuples like this:
[(\'grape\', 100), (\'grape\', 3), (\'apple\', 15), (\'apple\', 10), (\'apple\', 4), (\'banana\', 3)]
>>> from itertools import groupby >>> from operator import itemgetter >>> L=[('grape', 100), ('grape', 3), ('apple', 15), ('apple', 10), ('apple', 4), ('banana', 3)] >>> [(x,sum(map(itemgetter(1),y))) for x,y in groupby(L, itemgetter(0))] [('grape', 103), ('apple', 29), ('banana', 3)]