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




No comments:

Post a Comment