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
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'
>
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
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
John Machin wrote:
G. Völkl wrote:
I use a dictionary:
phone = {'mike':10,'sue':8,'john':3}
Of course in the real world using given name as a unique key is
ludicrous: 'mike' is a.k.a. 'michael' (or 'mikhail' or 'michele' (which
may be a typo for 'michelle')), and if there's only one 'sue' in your
l
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':
"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
<[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
[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:
phon
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 [
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
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
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
13 matches
Mail list logo