[Python-Dev] Python 3.x and bytes (original) (raw)

Nick Coghlan ncoghlan at gmail.com
Fri May 20 11:21:24 CEST 2011


On Fri, May 20, 2011 at 10:40 AM, Ethan Furman <ethan at stoneleaf.us> wrote:

This behavior matches what I was imagining for having b'a' == 97.  They compare equal, yet remain distinct objects for all other purposes.

If anybody has a link to or an explanation why equal values must be equal hashes I'm all ears.  My apologies in advance if this is an incredibly naive question.

Because whether or not two objects can coexist in the same hash table should not depend on their hash values - it should depend on whether or not they compare equal to each other. The use of hashing should just be an optimisation, not fundamentally change the nature of the comparison operation. (i.e. "hash(a) == hash(b) and a == b" is meant to be a fast alternative to "a == b", not a completely different check).

Cheers, Nick.

-- Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-Dev mailing list