For every element in a for loop, I want to check if the element satisfies some condition. If yes, I want to do something to it; if no, I want to add it to the end of the list and do it later.
I'm aware that modifying loops while looping is bad, but I want to do it anyway, and want to know how to do it correctly.
for i in list:
if something(i):
do(i)
else:
#append to end of list, do later
list.remove(i)
list.append(i)
This piece of code mostly works, but causes me to skip the element after the removed i while iterating. How do I work around that?