New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve SeqIter documentation #90253
Comments
The language reference about the 'for' statement (https://docs.python.org/3/reference/compound_stmts.html#the-for-statement) has a "Note" box that states that the for statement uses an "internal counter" which is "incremented", and goes into detail about what happens when modifications happen before or after the current loop position. Surely this depends on the underlying iterator? For example, with a balanced tree an insert or a delete could completely re-jigger the tree with hard-to-predict results on an iterator. |
The note does say it’s about mutable sequences like lists. |
I think this note can be removed. The tutorial now has coverage of mutating while iterating. That is the correct place for discussion of looping techniques. The part about the "internal counter" needs to be rewritten and moved to stdtypes.rst section on Sequence types. Here is a first draft: "Forward and reversed iterators over sequences access values using an index. That index will continue to march forward (or backward) even if the underlying sequence is mutated. The iterator terminates only when an IndexError or StopIteration is encountered (or when the index drops below zero)." Sequence iterators are roughly equivalent to: def seqiter(seq):
i = 0
while True:
try:
yield seq[i]
except (IndexError, StopIteration):
break
i += 1 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: