newbie: dictionary - howto get key value

Michael.Coll-Barth at VerizonWireless.com Michael.Coll-Barth at VerizonWireless.com
Thu Mar 10 12:34:44 EST 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]
       break

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:
python-list-bounces+michael.coll-barth=verizonwireless.com at python.org
[mailto:python-list-bounces+michael.coll-barth=verizonwireless.com at pytho
n.org]On Behalf Of G. Völkl
Sent: Thursday, March 10, 2005 12:19 PM
To: python-list at python.org
Subject: newbie: dictionary - howto get key value


Hello,

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 ?

Thanks
       Gerhard


-- 
http://mail.python.org/mailman/listinfo/python-list
___________________________________________________________________
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