looking up dictionaries by values

Sandman enjoylife_95135 at hotmail.com
Fri Mar 11 03:26:50 CET 2005


Hi there,
  I'm still a bit new to Python, and had a question.
I have a dictionary that looks like:
PWD = \
  {
   "root":     0,
   "joe":     200,
   "susan":   201,
..
}

  In other words, the values are unique as well as the keys. I've run
into a situation where I need to lookup the item by value. So given
201, I need to say the key is really susan.

 Is there a way to do this that does not traverse the entire dictionary
multiple times?

Thanks.




More information about the Python-list mailing list