[Python-Dev] PEP 469: Restoring the iterkeys/values/items() methods

Kristján Valur Jónsson kristjan at ccpgames.com
Mon Apr 21 16:02:12 CEST 2014



> -----Original Message-----
> From: Python-Dev [mailto:python-dev-
> bounces+kristjan=ccpgames.com at python.org] On Behalf Of Steven
> D'Aprano
> If this is a cunning plan to make Nick's suggestion sound better by suggesting
> an even worse alternative, it's working :-)

You got me.
However, I also admit to having learned something today from the PEP.  That 2to3 actually replaces d.iteritems() with iter(d.items()).
In all my porting experience this conservative approach is redundant for my use cases which is usally just immediate iteration, so I have successfully replaced d.iteritems() with d.items() without issue.  For polyglot code, with rare exceptions simply using d.items() in both places is good enough, since IMHO the ill effects of creating temporary list objects is somewhat overstated.

The PEP however explicitly wants to do it "correctly" because testing is often limited.  So I withdraw my suggestion :)

K


More information about the Python-Dev mailing list