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: Python Tutorial should introduce iterators and generators
Type: enhancement Stage:
Components: Documentation Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jim Fasarakis-Hilliard, docs@python, mkesper, rhettinger
Priority: normal Keywords:

Created on 2017-01-30 10:05 by mkesper, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg286480 - (view) Author: Michael Kesper (mkesper) Date: 2017-01-30 10:05
Please look at http://stackoverflow.com/questions/41932287/how-can-i-create-a-loop-for-these-if-statements/41932494?noredirect=1#41932494 

For beginners, it would be good to introduce the concepts of 'pythonic' dealing with sequences (iterators) and streams (generators) as soon as possible and everywhere where sequenceable data structures are discussed.

It is a common idiom in other languages to access members of sequences with counters, risking off-by-one errors or IndexErrors.

If beginners aren't introduced to the 'right' concepts soon enough, they might have a hard time figuring out the 'iterator' way.
Iterators should at least be mentioned in https://docs.python.org/3/tutorial/datastructures.html#looping-techniques.
msg286485 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-01-30 11:37
What change do you have in mind for introducing these?

As for my personal opinion, dunno about this. I understand your concerns but dropping more terminology to a new learner early on wouldn't be the best idea in my view. 

From what I am aware, Python is not becoming one of the *first* languages people learn due to its friendly nature. Adding concepts like generators and iterators when a new user is struggling with appends and mutability doesn't seem like it would help. 

BTW, iterators and generators are discussed in the Classes section of the tutorial, don't you think this suffices?
msg286486 - (view) Author: Jim Fasarakis-Hilliard (Jim Fasarakis-Hilliard) * Date: 2017-01-30 11:38
Typo, is *now* becoming :-)
msg286512 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-01-31 03:41
IMO, the iterators are introduced at the correct point.  

There are many topics that one could argue should be introduced early, but of course they can't all go earlier (classes should be introduced earlier because everything in python is an object; namespaces should be introduced earlier because they are core concept that affects everything from function locals, to closures, classes, instances, and modules).

I concur with Jim that dropping more terminology earlier in the tutorial doesn't serve the user well.
History
Date User Action Args
2022-04-11 14:58:42adminsetgithub: 73576
2017-01-31 03:41:57rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg286512

resolution: rejected
2017-01-30 11:38:14Jim Fasarakis-Hilliardsetmessages: + msg286486
2017-01-30 11:37:44Jim Fasarakis-Hilliardsetnosy: + Jim Fasarakis-Hilliard
messages: + msg286485
2017-01-30 10:05:09mkespercreate