def delete_starting_evens(lst):
i = 0
while i in range(len(lst)):
if lst[i] % 2 == 0:
lst = lst[1:]
continue
i = i + 1
else:
break
return lst
Hello guys,
So I finally found what seems to be the solution to this problem but when I think about what the program does step by step there’s something I don’t get:
- While i is in the range of the full list : so the full list, at that time, contains n elements, and i starts with 0
- the program goes on, the list get sliced, and finally i gets incremented by 1. Now the list has n-1 elements, and i = 1. And we loop back to start.
This is where I don’t get it. Because in this new loop, i would look for the position 1 in the new list, but in this new list, the position 1 is held by what used to be the third element in the unsliced list, aka the former position 2. So I would assume that by writing the code this way, i would be skipping the element in between from the list. Yet it doesn’t.
What am I thinking wrong please?
Hope I was clear enough … Thanks anyway =)