This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients eric.smith, paul.moore, sreedevi.ha, steven.daprano, terry.reedy
Date 2020-09-13.05:00:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1599973232.93.0.535967750416.issue41774@roundup.psfhosted.org>
In-reply-to
Content
Sreedevi: the Windows tag is meant for issues that involve Windows behavior that is different from other OSes; the IDLE tag is meant for issues that involve the behavior of IDLE, as distinct from other ways of running Python code.  They should not be used just because you ran code from IDLE on Windows.

There are two aspects to mutating while iteration: correctness and speed.  For beginners, the general advice "Don't do it" is not bad.  However:
  
Removing items from a list *works* when iterating in reverse if removal is done by index (del mylist[i] rather than value (mylist.remove(value)).  But it turns an inherently O(n:=len(list)) operation into a slow O(n*n) operation.  

The usually recommended alternative is to make a new list of things not deleted.  But one can do this in-place by writing the new list on top of the old by using a explicit second index to move items just once.

I reopened to add to the programming FAQ Sequences (Tuples/Lists) section
How do you remove multiple items from a list?
after the current
How do you remove duplicates from a list?
History
Date User Action Args
2020-09-13 05:00:32terry.reedysetrecipients: + terry.reedy, paul.moore, eric.smith, steven.daprano, sreedevi.ha
2020-09-13 05:00:32terry.reedysetmessageid: <1599973232.93.0.535967750416.issue41774@roundup.psfhosted.org>
2020-09-13 05:00:32terry.reedylinkissue41774 messages
2020-09-13 05:00:32terry.reedycreate