P
Paul Melis
Hello,
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:
...
and found that it seems to perform a lot better when lots of key-tests
are to be performed. I also noticed that has_key() is scheduled to be
removed from future (C)Python versions.
Does the 'in' way of testing have an optimized implementation compared
to has_key()? Is that the reason has_key() is being phased out?
Thanks,
Paul
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:
...
and found that it seems to perform a lot better when lots of key-tests
are to be performed. I also noticed that has_key() is scheduled to be
removed from future (C)Python versions.
Does the 'in' way of testing have an optimized implementation compared
to has_key()? Is that the reason has_key() is being phased out?
Thanks,
Paul