New submission from Tim Peters <>:

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 

- 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@python
components: Documentation
messages: 311614
nosy: docs@python, tim.peters
priority: normal
severity: normal
stage: needs patch
status: open
title: Mutating a list while iterating:  clarify the docs
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

Python tracker <>
Python-bugs-list mailing list

Reply via email to