$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · hard · #48

What is the correct fix?

def remove_evens(nums):
    for n in nums:
        if n % 2 == 0:
            nums.remove(n)
    return nums
  1. Change remove(n) to pop(n)
  2. Change == 0 to != 0
  3. Iterate a copy: for n in nums[:]:
  4. Return a new empty list
Removing while iterating skips items; loop over a copy.
Play Problem Solving ▸