[docs] [issue16225] list.remove in for loop

Georg Brandl report at bugs.python.org
Sun Oct 14 20:31:14 CEST 2012


Georg Brandl added the comment:

Well, I guess Serhiy meant "neither increase nor decrease".

In the end, the exact behavior will never be clear if you don't state explicitly how it's implemented: a counter that starts at 0 and is increased on __next__ until it's equal to len(list) (as checked at every iteration step).  But in general the advice should be: if you want to insert or remove elements during iteration, iterate over a copy.

----------
nosy: +georg.brandl

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16225>
_______________________________________


More information about the docs mailing list