$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #145

What is the correct fix?

for item in items:
    if item.stale:
        items.remove(item)
  1. Build a new filtered list
  2. Iterate the list backwards
  3. Call remove after the loop
  4. Use items.pop() instead
Removing while iterating shifts the list and silently skips elements.
Play Problem Solving ▸