"for loop" breaks after the "if statement" in it is True once

Viewed 32
  1. def filter_list(list):
    for x in list:
        if isinstance(x, str) == True:
            list.remove(x)
        else:
            pass
    return list
    

input: [1, 2, "a", "b"]

output: [1, 2, 'b']

The for loop breaks after the "if statement" in it is true.

0 Answers
Related