lost Hashability with __cmp__
Michael Hudson
mwh at python.net
Wed Jan 29 09:33:19 EST 2003
Martin Schmettow <martin.schmettow at bibliothek.uni-regensburg.de> writes:
> Hi all.
>
> I declared a __cmp__ for a class. Now I get an TypeError: unhashable
> instance if I use objects of this class as keys in a dictionary.
> Can someone explain why and how I can gain back hashability?
Define a __hash__ method. Make sure that instances that __cmp__ equal
generate the same hash code.
Cheers,
M.
--
112. Computer Science is embarrassed by the computer.
-- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html
More information about the Python-list
mailing list