How do I get a reference to a KEY value of a dictionary?

Aahz aahz at pythoncraft.com
Tue Aug 5 11:05:31 EDT 2003


In article <jyFXa.342$TC.22669471 at newssvr13.news.prodigy.com>,
Andy C <ayc8NOSPAM at cornell.edu> wrote:
>
>OK, you're right -- I assumed that the key and value were duplicated,
>but that's not the case.  I don't know why I thought that, maybe since
>the key must be immutable and the value is mutable.  So I guess having
>a dictionary of the form { 'A': 'A', 'B': 'B' } is not as stupid as it
>first seems, since only a reference is stored.  But still I wonder why
>the language doesn't have a facility for getting a reference to the key
>value in constant time.  Apparently someone did it by modifying the C
>source for the dictionary to add a ref_key() accessor.  It seems like
>it would be useful quite often.

Well, you're the first person I recall caring about this specific issue.
Of course, general caching issues come up quite frequently.  All the
people I've seen wanting to use intern() come at it from a performance
rather than memory perspective, for which a dict would be no use.  ;-)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

This is Python.  We don't care much about theory, except where it intersects 
with useful practice.  --Aahz




More information about the Python-list mailing list