newbie: dictionary - howto get key value

Michael.Coll-Barth at Michael.Coll-Barth at
Thu Mar 10 18:34:44 CET 2005

how about?

test = 3   #find person with this number
for x in xrange(len(phone.keys())):
    print x
    if phone[phone.keys()[x]] == test:
       print phone.keys()[x]

Being a newbie myself, I'd love a little critique on the above.  Be kind as
I don't know what else needs to be done in Gerhard's process.  Of course, we
could put this loop in a call and return the name

-----Original Message-----
From: at
[ at pytho]On Behalf Of G. Völkl
Sent: Thursday, March 10, 2005 12:19 PM
To: python-list at
Subject: newbie: dictionary - howto get key value


I use a dictionary:

phone = {'mike':10,'sue':8,'john':3}

phone['mike']   --> 10

I want to know who has number 3?

3 -->  'john'

How to get it in the python way ?


The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure.  If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof.  Thank you.

More information about the Python-list mailing list