[Tutor] more dictionary fun

D-Man dsh8290@rit.edu
Tue, 6 Mar 2001 21:23:40 -0500


On Wed, Mar 07, 2001 at 11:57:04AM +1100, ewe2@can.org.au wrote:
| hi,
| 
| I have a dictionary in the form of {('A':(1,0)),('B':(2,1))} where the values
| are guaranteed to be unique. Given a specific value (e.g. (3,0)), how do i
| lookup the key?

# 'd' is a dictionary
# 'value_i_want' is the value you have and you want the key for it

for key , value in d.items() :
    if value == value_i_want :
        break

print "The key is" , key

-D