[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
...
> > if 'a' in thedict:
> > ...
> >
> > There's no need for the call to keys().
>
> Why not
>
> if thedict.has_key('a'):
> pass
> elde:
> pass
has_key exists only for backwards compatibility; the 'in' operator is
preferable.
$ python -mtimeit -s'd={}' 'd.has_key(23)'
1000000 loops, best of 3: 0.289 usec per loop
$ python -mtimeit -s'd={}' '23 in d'
10000000 loops, best of 3: 0.139 usec per loop
Why consume twice as much time with no advantages whatever?!
Alex
--
http://mail.python.org/mailman/listinfo/python-list