newbie: dictionary - howto get key value

John Machin sjmachin at lexicon.net
Sat Mar 12 02:28:48 EST 2005


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, 'helen' : 10}

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
little black book you need to get out more :-)




More information about the Python-list mailing list