Multilevel dicts/arrays v. tuples as keys?

alex23 wuwei23 at gmail.com
Mon Nov 14 22:07:34 EST 2011


Peter Otten <__pete... at web.de> wrote:
> If you need lookup only I'd prefer tuples, but sometimes you may want to
> retrieve all values with a certain k1 and
>
> d[k1]
>
> is certainly more efficient than
>
> [(k2, v) for (k1, k2), v in d.items() if k1 == wanted]

This was the hidden cost of the tuple/reverse-dictionary solution I
offered. The solution will of course depend on what the OP requires to
be more efficient: looking up keys from values, or working with
subsets of the data.



More information about the Python-list mailing list