hash and __eq__

Aaron Brady castironpi at gmail.com
Sat May 30 14:20:47 EDT 2009


I am writing a mapping object, and I want to ask about the details of
__hash__ and __eq__.  IIUC if I understand correctly, the Python
dict's keys' hash codes are looked up first in O( 1 ), then all the
matching hash entries are compared on equality in O( n ).  That is,
the hash code just really narrows down the search.  Am I correct?

P.S.  I always feel like my posts should start like, "A mapping object
am writing I."  Not too many verbs you can do that with in English.
What if I did it?



More information about the Python-list mailing list