Hello Codecademy,
In the code challenges, below is the problem statement:
Write a function called delete_starting_evens() that has a parameter named lst .

The function should remove elements from the front of lst until the front of the list is not even. The function should then return lst .

For example if lst started as [4, 8, 10, 11, 12, 15] , then delete_starting_evens(lst) should return [11, 12, 15] .

Make sure your function works even if every element in the list is even!

and i tried solving it by following the below code :slight_smile:
def delete_starting_evens(lst):

for num in lst:

if num%2 == 0:lst.remove(num)


return lst

#Uncomment the lines below when your function is done

print(delete_starting_evens([4, 8, 10, 11, 12, 15]))

print(delete_starting_evens([4, 8, 10]))

however the code is turning out wrong as output is being shown as
[8, 11, 15]

can u help telling me why ?

Trying to remove items from a list while iterating through it is messy.
You could iterate through the list using the index - it may be more straightforward.

What you had doesn’t work correctly:

lst = [4, 8, 10, 11, 12, 15] for num in lst: if num % 2 == 0: lst.remove(num) print(lst)

thanks a lot @janbazant1107978602