What is the correct fix?
for item in items:
if item.stale:
items.remove(item)
- Build a new filtered list
- Iterate the list backwards
- Call
removeafter the loop - Use
items.pop()instead
Removing while iterating shifts the list and silently skips elements.
Play Problem Solving ▸