In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> On Apr 24, 1:41 pm, Steven Bethard <[EMAIL PROTECTED]> wrote:
>> Steven Howe wrote:
>>
>> > or try:
>> > thedict = { 'a': 1, 'b':2, 'c':3 }
>> > if 'a' in thedict.keys():
>> >    print thedict['a']
>>
>> Better yet, just:
>>
>>      if 'a' in thedict:
>>          ...
>>
>> There's no need for the call to keys().
> 
> Why not
> 
> if thedict.has_key('a'):
>     pass
> elde:
>     pass

Additional to the speed argument, the ``in`` operator works with more
types, like lists, sets and "iterables".  And if someone implements a
"container" class with membership testing, it is more likely he writes a
`__contains__()` method than a `has_key()` method.

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to