How to delete list elements while cycling the list itself without duplicate it
问题 I lost a little bit of time in this Python for statement: class MyListContainer: def __init__(self): self.list = [] def purge(self): for object in self.list: if (object.my_cond()): self.list.remove(object) return self.list container = MyListContainer() # now suppose both obj.my_cond() return True obj1 = MyCustomObject(par) obj2 = MyCustomObject(other_par) container.list = [obj1, obj2] # returning not an empty list but [obj2] container.purge() It doesn't work as I expected because when the