dictionary sub-value lookup

Mikael Olofsson mikael at isy.liu.se
Thu Feb 8 07:15:00 EST 2001


On 08-Feb-01 Richard wrote:
 >  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.
 >  
 >  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).

Just my two cents:

If you are going to do a lot of lookups of this kind, I think you
should consider preprocessing the data, thus transforming

  {'Label': 251, 'value': 1275.0}

to 

  {251: 1275.0}

and after that do your lookups.

I leave the funky OO-stuff to others.

/Mikael

-----------------------------------------------------------------------
E-Mail:  Mikael Olofsson <mikael at isy.liu.se>
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael               
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    08-Feb-01
Time:    13:09:03

         /"\
         \ /     ASCII Ribbon Campaign
          X      Against HTML Mail
         / \

This message was sent by XF-Mail.
-----------------------------------------------------------------------



More information about the Python-list mailing list