Python version of STL multimap?
Gerhard Häring
gerhard.haering at gmx.de
Sat Jul 6 17:13:24 EDT 2002
* Roy Smith <roy at panix.com> [2002-07-06 16:42 -0400]:
> I often want to create a dictionary whose values are lists of items
> with the same key. I've got variations on [snip]
This is what I use:
d[key] = d.get(key, []) + [value]
Gerhard
--
mail: gerhard <at> bigfoot <dot> de registered Linux user #64239
web: http://www.cs.fhm.edu/~ifw00065/ OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9 3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))
More information about the Python-list
mailing list