FAQ: Code Challenge: Loops - Delete Starting Even Numbers

Hm, so I was hoping “if len(lst) > 0:” would handle the empty list;
as for the i variable, I was thinking it would be necessary for the .pop(i) but I take it from your reply .pop(0) will do the same job

1 Like

It will catch it on the inputs, but not in the loop.

Aah gotcha, so after the popping commences it won’t kick in. I’ll try and adapt it. Thanks for the help!

1 Like
def delete_starting_evens(lst):
  if len(lst) > 0:
    while lst[0] % 2 == 0:
      if len(lst) == 1:
        return lst
    return lst
    return lst

totally worked! Thank you! Not so pretty perhaps but hey, satisfying af

What if that line returns a list with an even number in it?

…back to the drawing board

1 Like

Okay, so I’m interested to know why the following code doesn’t work (specifically the “continue” part. I understand the given solution (using lst = lst[1:], but I think the way on that the picture shows also makes sense…

Hi @py1026655807,

Your continue statement causes the following statement to be skipped during every iteration of the while loop, so i never gets incremented:

    i += 1

See 4.4. break and continue Statements, and else Clauses on Loops.

Thanks a lot :slight_smile:

1 Like