Re: newbie: dictionary - howto get key value

2005-03-14 Thread Peter Otten
Joal Heagney wrote: Does python guarantee that the lists given by phone.values() and phone.keys() are in mutual order? Or is it possible that python will return the lists in different orders for .values() and .keys()? Yes. Quoted from http://docs.python.org/lib/typesmapping.html: Keys and

Re: newbie: dictionary - howto get key value

2005-03-13 Thread Joal Heagney
Tim Roberts wrote: G. Völkl [EMAIL PROTECTED] wrote: 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 ? If you need to do this a lot, just keep two dictionaries, where the keys in each are

Re: newbie: dictionary - howto get key value

2005-03-13 Thread Bengt Richter
On Mon, 14 Mar 2005 05:02:25 GMT, Joal Heagney [EMAIL PROTECTED] wrote: Tim Roberts wrote: G. Völkl [EMAIL PROTECTED] wrote: 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 ?

Re: newbie: dictionary - howto get key value

2005-03-12 Thread Bengt Richter
On Thu, 10 Mar 2005 18:56:41 +0100, bruno modulix [EMAIL PROTECTED] wrote: G. Völkl wrote: 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' Note that you can have many keys with the same value: phone

Re: newbie: dictionary - howto get key value

2005-03-11 Thread John Machin
bruno modulix wrote: G. Völkl wrote: 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' Note that you can have many keys with the same value: phone = {'mike':10,'sue':8,'john':3, 'jack': 3,

newbie: dictionary - howto get key value

2005-03-10 Thread G. Völkl
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

RE: newbie: dictionary - howto get key value

2005-03-10 Thread Michael . Coll-Barth
to be done in Gerhard's process. Of course, we could put this loop in a call and return the name -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] n.org]On Behalf Of G. Völkl Sent: Thursday, March 10, 2005 12:19 PM To: python-list@python.org Subject: newbie: dictionary - howto

Re: newbie: dictionary - howto get key value

2005-03-10 Thread Diez B. Roggisch
phone = {'mike':10,'sue':8,'john':3} print [key for key, value in phone.items() if value == 3] - ['john'] -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie: dictionary - howto get key value

2005-03-10 Thread bruno modulix
G. Völkl wrote: 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' Note that you can have many keys with the same value: phone = {'mike':10,'sue':8,'john':3, 'jack': 3, 'helen' : 10} How to get it in the python way ?

Re: newbie: dictionary - howto get key value

2005-03-10 Thread Jeremy Jones
G. Völkl wrote: 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 How 'bout a list comprehension: In [1]:phone = {'mike':10,'sue':8,'john':3, 'billy':3} In

Re: newbie: dictionary - howto get key value

2005-03-10 Thread bruno modulix
[EMAIL PROTECTED] wrote: (top-post corrected) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] n.org]On Behalf Of G. Völkl Sent: Thursday, March 10, 2005 12:19 PM To: python-list@python.org Subject: newbie: dictionary - howto get key value Hello, I use a dictionary

Re: newbie: dictionary - howto get key value

2005-03-10 Thread Richard Brodie
[EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] 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.