Terry J. Reedy <tjre...@udel.edu> added the comment:

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?

----------
nosy: +terry.reedy
resolution: not a bug -> 
stage: resolved -> needs patch
status: closed -> open
versions: +Python 3.10 -Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41774>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to