[docs] [issue32767] Mutating a list while iterating: clarify the docs
report at bugs.python.org
Sun Feb 4 14:27:00 EST 2018
New submission from Tim Peters <tim at python.org>:
This has come up repeatedly, and the docs should be updated to resolve it:
Seemingly the only relevant documentation is in the reference manual, but it's flawed:
- The behavior it's describing is specific to list iterators, but it pretends to apply to "mutable sequences" in general (which may or may not mimic list iterators in relevant respects).
- It's not clear that the "length of the sequence" (list!) is evaluated anew on each iteration (not, e.g., captured once at the start of the `for` loop).
- While it describes things that can go wrong, it doesn't describe the common useful case: appending to a list during iteration (for example, in a breadth-first search).
assignee: docs at python
nosy: docs at python, tim.peters
stage: needs patch
title: Mutating a list while iterating: clarify the docs
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
Python tracker <report at bugs.python.org>
More information about the docs