[Python-ideas] Suggestion for Style Guide for Python Code PEP 8
Georg Brandl
g.brandl at gmx.net
Thu May 12 22:12:47 CEST 2011
On 12.05.2011 15:44, Rahul Amaram wrote:
> Hi,
> I was wondering if the following programming recommendation would be
> added to the Style Guide for Python Code (PEP 8) page.
>
> The preferred way for checking if a key (k) exists in a dictionary (d)
> is "if k in d". This is faster than "if k in d.keys()" and this has
> superseded "d.has_key(k)"
While "k in d" is certainly the right way, this is not the sort of thing
that should be added to PEP 8. There must be dozens of such little
idioms and anti-idioms, and listing them all is way beyond the PEP's scope.
(And has_key is gone in py3k anyway.)
Georg
More information about the Python-ideas
mailing list