[Python-ideas] An identity dict

Terry Reedy tjreedy at udel.edu
Mon May 31 20:05:57 CEST 2010


It appears that different people are talking about two different ideas 
of identity dict, with different properties and possible use cased. So 
the statement of some do not apply to the idea held by others.

A. key object is not stored in dict.
    d[k] = o ==> _d[id(k)] = o
Faster but limited in that cannot extract keys and user code must keep 
keys alive.

B. key object stored in dict in one of at least two ways.
    1. d[k] = o ==> _d[id(k)] = (k,o)
    2. d[i] = o ==> i=id(k); _dk[i] = k; _do[i] = o
Slower, but (I believe) can fully emulate dicts.

Either type can be generalized to f instead of id as the key transform.


current vote: -.3
I am also not yet convinced, but perhaps could be, that either type, 
with or without generalization should be in the stdlib. Instances of 
user class without custom equality are already compared by identity. The 
use cases for keying immutables by identify is pretty sparse. That 
pretty much leave mutables with custom equality (by value rather than 
identity).

Terry Jan Reedy






More information about the Python-ideas mailing list