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

Guido van Rossum guido at python.org
Sat Apr 19 16:52:55 CEST 2014


Does everyone involved know that "for x in d.iterkeys()" is equivalent to
"for x in d" and works the same in Python 2 and 3? Similarly, "list(d)" is
a simple, fast way to spell the Python 2 semantics of "d.keys()"  that
works in both versions (but I doubt it is much needed -- usually the actual
code follows up with sorting, so you should use sorted(d)).

This doesn't solve itervalues() and iteritems() but I expect those are less
common, and "for x, y in d.iteritems(): <blah>" is rewritten nicely as

  for x in d:
    y = d[x]
    <blah>

If there is a measurable slowdown in the latter I would be totally okay
with some kind of one-element cache for the most recent lookup.

I get the social aspect of the PEP, but I think it's too high a price to
pay.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140419/dec2082b/attachment.html>


More information about the Python-Dev mailing list