My Tech Notes
Search This Blog
Python: remove an item from list while iterating the list
list[:] = [item for item in list if match(item)]
The above code removes the matching items in the list without constructing a new list, therefore, the references to the list remain valid.
see also
Remove items from a list while iterating in Python
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment