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
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
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 ?
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
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,
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
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
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
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 ?
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
[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
[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.
12 matches
Mail list logo