dict.has_key(x) versus 'x in dict'

Bjoern Schliessmann usenet-mail-0306.20.chr0n0ss at spamgourmet.com
Wed Dec 6 08:46:22 EST 2006


Paul Melis wrote:

> I've always been using the has_key() method to test if a
> dictionary contains a certain key. Recently I tried the same using
> 'in', e.g.
> 
> d = { ... }
> if k in d:
>     ...

Wouldn't be "if k in d.keys()" be the exact replacement?

Regards,


Björn

-- 
BOFH excuse #17:

fat electrons in the lines




More information about the Python-list mailing list