Any built-in ishashable method ?

Peter Otten __peter__ at web.de
Sat Jan 19 02:53:22 EST 2013


Kushal Kumaran wrote:

> Peter Otten <__peter__ at web.de> writes:
> 
>> Jean-Michel Pichavant wrote:
>>
>>> That brings me to another question, is there any valid test case where
>>> key1 != key2 and hash(key1) == hash(key2) ? Or is it some kind of design
>>> flaw ?
>>
>> I don't think there is a use case for such a behaviour other than
>> annoying your collegues ;)
>>
> 
> It's fairly common.  The set of possible keys can be much larger
> (possibly infinite) than the set of possible hash values (restricted to
> 32-bit or 64-bit integer values, afaict).

Sorry, I misread the quoted text. If you replace

key1 != key2 and hash(key1) == hash(key2)

in Jean-Michel's question with

key1 == key2 and hash(key1) != hash(key2)

my reply should start to make sense...




More information about the Python-list mailing list