On 12/16/2014 08:18 PM, R. David Murray wrote:
On Tue, 16 Dec 2014 10:48:07 -0800, Mark Roberts <wiz...@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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com