Well, I'm not sure if this is what you want, but you could use a dictionary:
>>> d={} >>> for i,e in L: if d.has_key(i): d[i] += e else: d[i] = e >>> d {'A': 500, 'B': 200} >>> -- http://mail.python.org/mailman/listinfo/python-list
Well, I'm not sure if this is what you want, but you could use a dictionary:
>>> d={} >>> for i,e in L: if d.has_key(i): d[i] += e else: d[i] = e >>> d {'A': 500, 'B': 200} >>> -- http://mail.python.org/mailman/listinfo/python-list