dictionary sub-value lookup

Simon Brunning SBrunning at trisystems.co.uk
Thu Feb 8 06:40:08 EST 2001


> From:	Richard [SMTP:richard at millinfo.co.za]
> The object comes from a program.  I have no control over it.
> Example of M[0]:
> ({'Label': 251, 'value': 1275.0})
 
Ah-ha, I think that I get it. You don't have a big dictionary, you have a
tuple containing lots of small dictionaries. Correct?
 
> I just throught there was some easy way of getting M[i] given that
> M[i]['Label'] = 251 ... when what I really want is M[i]['value']
> 
> ie: given '251', find corrosponding 1275.
 
So, given a value, you which to find the dictionary in your tuple for which
the key 'Label' maps to your value, and return the 'value' entry from that
dictionary. Correct?
 
> Bearing in mind, M is actually HUGE, and M[i] contains about 10
> lines of uninteresting data when printed.  There is a LOT of
> information here, and I would like the thing to be fast.  I just
> thought that maybe there was some funky python or OO way of doing
> it (since I am from a Fortran background).
 
If you want to retrieve just one value, then I think that you'll just want
to loop through the dictionaries looking for the one you want. If you want
to retrieve lots of values, you might want to build another dictionary keyed
by the 'Label' value, containing the 'value' value.

Do all the dictionaries have the same key values? I.e., do they all have
'Label' as a key and 'value' as a key?

Cheers,
Simon Brunning
TriSystems Ltd.
sbrunning at trisystems.co.uk




-----------------------------------------------------------------------
The information in this email is confidential and may be legally privileged.
It is intended solely for the addressee. Access to this email by anyone else
is unauthorised. If you are not the intended recipient, any disclosure,
copying, distribution, or any action taken or omitted to be taken in
reliance on it, is prohibited and may be unlawful. TriSystems Ltd. cannot
accept liability for statements made which are clearly the senders own.




More information about the Python-list mailing list