3 Comments

"Thus, if two objects have the same hash value, then a dictionary will consider them as identical keys."

If they are equal (like 1==True, 1.0 == 1). If they are not equal and have the same hash that is just a **hash collision**, and all the objects are stored, see: https://stackoverflow.com/questions/9010222/why-can-a-python-dict-have-multiple-keys-with-the-same-hash

Expand full comment

I got to start my day well with this :)

Thank you

Expand full comment

Interesting find! Does this belief, that dictionaries find a key based on the object's ID, originate from the requirement that dictionary keys have to be unique? I also read in Python documentation that "Dictionaries work by computing a hash code for each key stored in the dictionary using the hash()".

Expand full comment