I try to write a function that would eliminate string elements from the list and return the new list.
My solution is:
def foo(lst):
for i in lst:
if type(i) == str:
lst.remove(i)
print(lst)
return(lst)
Whereas the correct one is:
def foo(lst):
return [i for i in lst if not isinstance(i, str)]
Is not logic basically the same? Where is my mistake? Is some lists my code works, for some does not