dictionary sub-value lookup
Aahz Maruch
aahz at panix.com
Thu Feb 8 11:08:20 EST 2001
In article <3A826E2E.611F9DBD at millinfo.co.za>,
Richard <rhsteven at eng.uct.ac.za> wrote:
>Okie, <python newbie tries better explanation>:
>
>The object comes from a program. I have no control over it.
>Example of M[0]:
>({'Label': 251, 'value': 1275.0})
>
>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.
For starters, you probably want a real database for this kind of thing.
That way, someone else has already done the work. But if you really
want to do this in Python, you need to create a dict that looks
something like this:
M[251] = (1275.0, 0)
If it's possible that more than one label of 251 will exist, you need to
do this:
M[251] = [(1275.0, 0), ...]
--
--- Aahz (Copyright 2001 by aahz at pobox.com)
Androgynous poly kinky vanilla queer het <*> http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6
"Actually, I've found that Usenet has helped a lot with my terror of
social stupidity. Seeing people I really like and respect behave like
idiots in public has been very beneficial." --Rachael Lininger
More information about the Python-list
mailing list