[Python-Dev] dict and required hashing

Jim J. Jewett jimjjewett at gmail.com
Fri Apr 18 23:46:35 CEST 2014


(1)  I believe the recent consensus was that the number of comparisons
made in a dict lookup is an implementation detail.  (Please correct me
if I am wrong.)

(2)  Is "the item will be hashed at least once" a language guarantee?

For small mappings, it might well be more efficient to just store the
2-3 key/value pairs and skip the bucket calculation.

On the other hand, if a key is not hashable, discovering that long
after it has already been added to the dict is suboptimal.

Of course, that sort of delayed exception can already happen if it is
the __eq__ method that is messed up ...

-jJ


More information about the Python-Dev mailing list