dictionary speed

Terry Reedy tjreedy at home.com
Fri Jul 13 23:10:39 EDT 2001


"David Bolen" <db3l at fitlinxx.com> wrote in message
news:uzoa81oa7.fsf at ctwd0143.fitlinxx.com...
> simonb at webone.com.au writes:
> If you have a three-level nested dictionary structure that you
> reference with something like:
>
>     dictionary[key1][key2][key3]
>
> then there are three discrete lookups occuring.  Of course, if you are
> going to be using that nested dictionary a lot, you could always bind
> a name to that dictionary while you use it, e.g.:
>
>     nested = dictionary[key1][key2]
>
> and then do single level lookups:
>
>     nested[key3]

I wonder whether the questioner is aware that one can use tuples, [in this
example (key1,key2,key3)] as keys in a one-level dictionary.  The
multi-level approach is only needed if one needs the nested dictionaries
for reduced-level lookups.

Terry J. Reedy






More information about the Python-list mailing list