What is the correct way to define __hash__?
lists at cheimes.de
Mon Oct 12 23:10:54 CEST 2009
Peng Yu schrieb:
> I'm wondering what is the general way to define __hash__. I could add
> up all the members. But I am wondering if this would cause a
> performance issue for certain classes.
> def __hash__(self):
> return self._a + self._b
The hash of a tuple is based on the hash of its values. A common way to
define a hash method is:
return hash((self._a, self._b))
More information about the Python-list