Mutable objects which define __hash__ (was Re: Why are tuplesimmutable?)

Fredrik Lundh fredrik at
Wed Dec 22 14:12:28 CET 2004

Nick Coghlan wrote:

> I have a different suggestion: an identity dictionary.
> It ignores __hash__, __cmp__ and __eq__, and instead uses id() and is.

that's a rather common pattern, and you don't really need a special type
to handle it: just replace d[k] with d[id(k)].  if you really need to store the
keys in the dict, use d[id(k)] = k, v.

you can find some use of this pattern in Python's standard library.


More information about the Python-list mailing list