Re: [Python-ideas] Suggestion for Style Guide for Python Code PEP 8

May 13, 2011
2:34 p.m.
On 12.05.2011 15:44, Rahul Amaram wrote:
While 'k in d' is the right way to do it, I feel the claim it's faster that 'k in d.keys()' is somewhat weak. While this is technically true, it's a constant overhead, not some cost linear in the size of the collection - at least in Python 3 - because .keys() returns a view.
So "x in d.keys()" is slower than "x in d", but only by the cost of a method lookup. I don't see any reason ever to recommend using "x in d.keys()", but I think it's misleading to say that this is because of performance reasons, assuming that we are talking about Python 3. (I also completely agree with everything Georg said, FWIW.)
5059
Age (days ago)
5059
Last active (days ago)
0 comments
1 participants
participants (1)
-
Weeble