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.

Author r.david.murray
Recipients docs@python, r.david.murray, rhettinger, terry.reedy, the_darklord
Date 2017-07-12.13:20:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1499865633.66.0.00727172991005.issue30826@psf.upfronthosting.co.za>
In-reply-to
Content
I don't think that helps.  The issue here is that *sequences* are iterated over by incrementing an integer index.  If you change the size of the list, you are potentially changing which value any given index points to.  Presumably the tutorial writer thought this was intuitive, and indeed after years of Python programming I find it so.  I can see how a beginner might not, though :)

What if we replaced:

  If you need to modify the sequence you are iterating over while inside the loop (for example to duplicate selected items), it is recommended that you first make a copy. Iterating over a sequence does not implicitly make a copy. The slice notation makes this especially convenient:

With:

  Sequence iteration is preformed by incrementing an implicit integer index until there are no more items in the sequence.  The sequence is *not* copied before iteration, so if you modify the sequence during iteration the value that is affected by the next iteration of the loop may not be the one you are expecting.  You can avoid this problem by iterating over a copy of the sequence, and the slice notation makes this especially convenient:

However, this section has a deeper problem.  It is introducing the 'for' statement, but explains what the for statement does in terms of sequences, when in fact the for statement now operates on any iterable, not just sequences.  (Many Python programmers probably do not remember the time before the iteration protocol was added to the language :)

Fixing that problem not only requires rewriting the section, but also figuring out the best place to introduce the concept of the iteration protocol (which *might* be in this section, but it's been so long since I've looked over the tutorial that I can't say).
History
Date User Action Args
2017-07-12 13:20:33r.david.murraysetrecipients: + r.david.murray, rhettinger, terry.reedy, docs@python, the_darklord
2017-07-12 13:20:33r.david.murraysetmessageid: <1499865633.66.0.00727172991005.issue30826@psf.upfronthosting.co.za>
2017-07-12 13:20:33r.david.murraylinkissue30826 messages
2017-07-12 13:20:33r.david.murraycreate