diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2022-01-01 18:37:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-01 18:37:26 (GMT) |
commit | a09bc3a404befca197b5d9959a9c62110ee61d77 (patch) | |
tree | 83f38b38e9d0114fdddb8046d22b375df65a357c /Doc/reference | |
parent | ac4eea21722d9ed1604c9c30a8d29ae2ce74f1b2 (diff) | |
download | cpython-a09bc3a404befca197b5d9959a9c62110ee61d77.zip cpython-a09bc3a404befca197b5d9959a9c62110ee61d77.tar.gz cpython-a09bc3a404befca197b5d9959a9c62110ee61d77.tar.bz2 |
bpo-46095: Improve SeqIter documentation. (GH-30316)
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/compound_stmts.rst | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index cf8ad17..03fc2cb 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -196,27 +196,6 @@ the built-in function :func:`range` returns an iterator of integers suitable to emulate the effect of Pascal's ``for i := a to b do``; e.g., ``list(range(3))`` returns the list ``[0, 1, 2]``. -.. note:: - - .. index:: - single: loop; over mutable sequence - single: mutable sequence; loop over - - There is a subtlety when the sequence is being modified by the loop (this can - only occur for mutable sequences, e.g. lists). An internal counter is used - to keep track of which item is used next, and this is incremented on each - iteration. When this counter has reached the length of the sequence the loop - terminates. This means that if the suite deletes the current (or a previous) - item from the sequence, the next item will be skipped (since it gets the - index of the current item which has already been treated). Likewise, if the - suite inserts an item in the sequence before the current item, the current - item will be treated again the next time through the loop. This can lead to - nasty bugs that can be avoided by making a temporary copy using a slice of - the whole sequence, e.g., :: - - for x in a[:]: - if x < 0: a.remove(x) - .. _try: .. _except: |