Confusion about dictionaries - keys use value or identity?
Alex Martelli
aleaxit at yahoo.com
Sun Jul 8 17:13:46 EDT 2001
"Roy Smith" <roy at panix.com> wrote in message
news:roy-58C72C.12353708072001 at news1.panix.com...
...
> Is there a way to force the comparison to be by identity? I'm
> contemplating building a cache (using a dictionary), and key comparison by
> identity should be significantly faster than by value, because I'm going
to
> be using rather long strings as keys.
You could try using the built-in function intern() on all strings involved.
That may cost you not a little memory (which garbage collection will
not recover) but there could be a substantial speed gain -- try it...
Alex
More information about the Python-list
mailing list