[Tutor] Performance difference, ``in'' vs ``has_key()''

André Roberge andre.roberge at gmail.com
Mon Jul 18 01:31:57 CEST 2005


Max Noel wrote:
> 
[snip]
> 
> 
>     While we're on that topic, is there a particular reason why  'in', 
> in a dict context, searches the keys instead of doing the  logical thing 
> and searching the values?
animals = { 'cat': "a cuddly little mammal who likes to eat birds",
'dog': "man's best friend, also a mammal and which also can eat birds",
'parrot': "a bird, favoured by Monty Python"}

What is more natural?

if parrot in animals: ....

or

if "a bird, favoured by Monty Python" in animals: ...

André



More information about the Tutor mailing list