Which fix removes the bug?
for i in range(len(items)):
if items[i] is None:
del items[i]
- Build a filtered list
- Sort the list first
- Use enumerate instead
- 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 ▸