Slow comparison between two lists

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Oct 23 09:57:54 EDT 2008


Hrvoje Niksic:
> You're right.  The OP states he implements __eq__, so he also needs a
> matching __hash__, such as:
>
>     def __hash__(self, other):
>         return (hash(self.xcoord) ^ hash(self.ycoord) ^
>                 hash(self.streetname) ^ hash(self.streetno))

The hash function by Otten is better because it considers the order of
the items too (while I think the xor doesn't):

return hash((self.xcoord, self.yccord, self.streetname,
self.streetno))

Bye,
bearophile



More information about the Python-list mailing list