I have a function remove_it() that tries to remove some data and the removed data is added to the set removed. The main logic is that if there is more to remove, keep removing and my code looks like this:
removed = set()
prev_count = -1
while prev_count != len(removed):
prev_count = len(removed)
remove_it()
It bothers me a little that the while loop condition and the next line look very similar to each other. Is it normal or is there a better way to do it?
The logic in remove_it() is quite complicated: it detects some graph structure topology and after each round of removal the topology changes and I cannot know how it changes until the removal is done.
I was thinking of return bool value from remove_it() to track whether the set removed has changed. Then the while loop would be like
while remove_it():
pass
which is also strange to me. Is there a better way?
while(function()) ;-- note the explicit semicolon. Nothing like that for Python?remove()and we are done: you thus say, "while removing, keep going".