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

Which fix removes the bug?

for i in range(len(items)):
    if items[i] is None:
        del items[i]
  1. Build a filtered list
  2. Sort the list first
  3. Use enumerate instead
  4. Convert to a tuple
Deleting shifts the tail left while range keeps counting, so items are skipped and indexes run past the end.
Play Problem Solving ▸