Any built-in ishashable method ?

Jean-Michel Pichavant jeanmichel at sequans.com
Fri Jan 18 06:56:09 EST 2013


 
> So I'm guessing you had a key where
> 
> key1 == key2 did not imply hash(key1) == hash(key2)
> 
> I don't see a way to avoid that problem in a look-before-you-leap
> test.
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 

You guessed right. But it took me a lot of time before jumping to that conclusion, mostly because the code worked in the first place (it can with a little bit of luck).
Now I'm extra careful about what I use as dict key, I was just wondering if there was a reliable quick way to verify an object can be used as key.

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 ?

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list