Using reverse iteration to clean up a list

Luis M. Gonzalez luismgz at gmail.com
Sat Mar 12 23:53:13 EST 2005


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}
>>>




More information about the Python-list mailing list