[issue41893] remove() method is not working as expected(Hard to explain)

Ben report at bugs.python.org
Wed Sep 30 11:54:04 EDT 2020


Ben <benjsimner at gmail.com> added the comment:

See the note in https://docs.python.org/3.7/reference/compound_stmts.html#the-for-statement "There is a subtlety when the sequence is being modified by the loop ..."

Since your code is mutating the  all_fields  list as you iterate it, you get the " next item will be skipped " behaviour, which is why the loop is skipping over "password".  remove() was never called to remove "password".

There is an open issue https://bugs.python.org/issue32767 to clarify the docs about this,  but it is not a bug in Python.

----------
nosy: +bjs

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


More information about the Python-bugs-list mailing list