Why lst.pop(0) will not give an empty list

Hello everyone, I’m wondering if someone could tell me what’s wrong with my code here, specifically why lst.pop(0) will not give an empty list for a list of all even numbers and gets stuck leaving the last number. I’m new to Python (and coding) as of three days ago so this is all new to me and I really appreciate any help!

#Write your function here def delete_starting_evens(lst): for num in lst: if num % 2 == 0: lst.pop(0) 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]))

If a list is empty, it has no definable element to pop. This will give an out of range error, one suspects.

What you’ve done looks sound, but because you’re altering the contents of lst inside the loop it’s not acting totally as you’d expect.
One way to tweak it is;

change the for loop to;
for num in range(len(lst)):
and then alter the if statement to check the first index of the list each time, i.e;
if lst[0] %2 == 0:

Hope that helps