-
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.
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.