This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Many usages of dict.keys(), dict.values(), dict.items() when the iter version could be used
Type: Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: loewis, ned.deily, skreft
Priority: normal Keywords:

Created on 2011-11-07 03:11 by skreft, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg147199 - (view) Author: (skreft) Date: 2011-11-07 03:11
In Python 2.7, there are many patterns of the form

for x in mapping.(keys()|values()|items()):
    #code
when the iterator version of those method could be used.
Is there any reason for using those methods?

I see that in some other parts of the code the iterator version is used. Here is the summary:

       Non iter version Iter version
Keys   160              21 
Values 35               23
Items  249              79

I sued the following command

$ egrep -R "for.*[.]iterkeys\(\)" . | wc -l 


What's the position about this? Does it worth it to fix this?
msg147204 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-11-07 06:41
Thanks for you interest in improving Python. As noted in the response to one of your other issues, we generally do not do style cleanups just for the sake of style cleanups.  In addition, our policy for current maintenance branches, like Python 2.7, is to apply bug fixes only.  As there will be no further feature releases for Python 2, anything other than a bug fix would only be a candidate for the next Python 3 release (Python 3.3).

See the Python Developer's Guide for more information:
http://docs.python.org/devguide/devcycle.html#maintenance-branches
msg147208 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2011-11-07 07:42
skreft: since you were asking for a reason why the code looks the way it looks - the code in many cases predates the introduction of iterkeys and friends.

I personally find the names iterkeys/itervalues/iteritems fairly ugly, and rather avoid them for prettiness reasons, unless there is a real problem that requires using iterators. Thankfully, the issue was resolved in Python 3, where .keys() does the right thing (i.e. returning a view).
History
Date User Action Args
2022-04-11 14:57:23adminsetgithub: 57572
2011-11-07 07:42:50loewissetnosy: + loewis
messages: + msg147208
2011-11-07 06:41:17ned.deilysetstatus: open -> closed

nosy: + ned.deily
messages: + msg147204

resolution: rejected
stage: resolved
2011-11-07 03:11:56skreftcreate