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

Terry Reedy tjreedy at udel.edu
Thu Jul 31 20:46:16 EDT 2003


"Andy C" <andychup at yahoo.com> wrote in message
news:645db655.0307311636.71923378 at posting.google.com...
> I am new to python, so please bear with me if I am making some
> conceptual error.
>
> Basically I want to create a graph with an adjacency list
> representation, but I don't want any of the adjacency lists to have
> duplicate strings when it is avoidable.  I have a function
createEdge
> that adds an edge to the graph.  The arguments will be distinct
since
> they are read from text files.  But basically I want to use the
> dictionary as a string pool, and if the argument string equals
> something in the pool already, don't use the argument string, just a
> use a reference to something in the string pool already.

Thinking in terms of 'references' can both help and hinder.  (There
have been some long recent discussion.)

Are you familiar with this?

>>> help('intern')

Help on built-in function intern:

intern(...)
    intern(string) -> string

    ``Intern'' the given string.  This enters the string in the
(global)
    table of interned strings whose purpose is to speed up dictionary
lookups.
    Return the string itself or the previously interned string object
with the
    same value.

TJR






More information about the Python-list mailing list