[Python-Dev] Python 2.x and 3.x use survey, 2014 edition

Hrvoje Niksic hrvoje.niksic at avl.com
Wed Dec 17 10:33:52 CET 2014


On 12/16/2014 08:18 PM, R. David Murray wrote:
> On Tue, 16 Dec 2014 10:48:07 -0800, Mark Roberts <wizzat at gmail.com> wrote:
>> > Besides, using iteritems() and friends is generally a premature
>> > optimization, unless you know you'll have very large containers.
>> > Creating a list is cheap.
[...]
> No.  A premature optimization is one that is made before doing any
> performance analysis, so language features are irrelevant to that
> labeling.  This doesn't mean you shouldn't use "better" idioms when they
> are clear.

This is a relevant point. I would make it even stronger: using 
iteritems() is not a premature optimization, it is a statement of 
intent. More importantly, using items() in iteration is a statement of 
expectation that the dict will change during iteration. If this is not 
in fact the case, then items() is the wrong idiom for reasons of 
readability, not (just) efficiency.



More information about the Python-Dev mailing list