Delete Starting Even Numbers for the list with every element except for the first one using lst[1:]

I don’t understand why we iterate thru the list and slice at lst[1:].
Wouldn’t that skip the index 0 where the first number starts?

def delete_starting_evens(lst):
while (len(lst) > 0 and lst[0] % 2 == 0):
lst = lst[1:]
return lst
print(delete_starting_evens([4, 8, 10, 11, 12, 15]))
print(delete_starting_evens([4, 8, 10]))
Thank you in advance!

Also, let’s say I want to use a random list replacing the [4, 8, 10, 11, 12, 15] or the [4, 8, 10] like for example [3,4,1,8,9,11] it seems this code will not work because of the slicing. How would I be able to code it to where it can iterate thru the whole list without it having to be sequential?

Might be worth printing the output of that slice on each iteration so you know what the result is. It might make more sense that way.

1 Like