My Tech Notes
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
‹
›
Home
View web version
No comments:
Post a Comment