dictionary sub-value lookup

Steve Holden sholden at holdenweb.com
Wed Feb 7 11:29:07 EST 2001


"Richard" <richard at millinfo.co.za> wrote in message
news:3A80F9B4.E072037D at millinfo.co.za...
> Hi
>
> I am kinda new to this whole object orientation thing, so
> there is probably an easy way of doing this, but the
> tutorials etc are sparse.
>
It takes a while to get used to the OO way of things, but it will pay
dividends so it's worth the effort.

> I have an object M which contains N dictionaries. Inside
> dictionary N, is an identifier, Y, plus various other
> values, eg: Z.... is it possible to find M.Y.Z without
> looping through the whole of M, checking Y each time ?
>
First obvious question is why are the dictionaries separate?

> Since I will have to do a LOT of this, and M may be large,
> I need a fast method.
>
> Ideas/comments etc ?
>
One simple speed-up, which may or may not help in your case, is to maintain
a global contents dictionary, where each key contains a list of the
dictionaries in which it is defined. That way you'll know exactly which
dictionaries it's worth searching. Of course there's some overhead involved
in this, so you'll have to evaluate the tradeoff.

More detail, or some code, might help in providing more relevant
suggestions.

regards
 Steve





More information about the Python-list mailing list