I have a set myset
, and I have a function which iterates over it to perform some operation on its items and this operation ultimately deletes the item from the set.
Obviously, I cannot do it while still iterating over the original set. I can, however, do this:
mylist = list(myset)
for item in mylist:
# do sth
Is there any better way?