[issue41774] While removing element from list using for and remove(), which has same items output is not right

Eric V. Smith report at bugs.python.org
Sat Sep 12 12:27:23 EDT 2020


Eric V. Smith <eric at trueblade.com> added the comment:

You should not mutate a list while iterating over it.

See, for example https://stackoverflow.com/questions/6260089/strange-result-when-removing-item-from-a-list

I couldn't find a place where this is mentioned in the python list docs. If it's not there, we should add something to the programming FAQ.

----------
nosy: +eric.smith

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41774>
_______________________________________


More information about the Python-bugs-list mailing list