I have a list of tuples:
[ (\'A\',100), (\'B\',50), (\'A\',50), (\'B\',20), (\'C\',10) ]
I am trying to sum up all numbers that have the s
A simpler approach
x = [('A',100),('B',50),('A',50),('B',20),('C',10)] y = {} for _tuple in x: if _tuple[0] in y: y[_tuple[0]] += _tuple[1] else: y[_tuple[0]] = _tuple[1] print [(k,v) for k,v in y.iteritems()]