FAQ: Code Challenge: Loops - Delete Starting Even Numbers

A post was merged into an existing topic: Why doesn’t iterating with for work while removing items from a list?

27 posts were merged into an existing topic: Why doesn’t iterating with for work while removing items from a list?

3 posts were split to a new topic: Infinite loop [solved]

4 posts were split to a new topic: How does break work? [solved]

8 posts were split to a new topic: Code challenge lists - improving my solution [solved]

3 posts were split to a new topic: Using continue in a while loop [solved]

7 posts were split to a new topic: How does this code loop I wrote work?

4 posts were split to a new topic: Why does my loop skip indexes of my list?

2 posts were merged into an existing topic: Why is len(lst) > 0 necessary for solving the list challenge?

4 posts were split to a new topic: Why doesn’t my code work how I expected?

15 posts were split to a new topic: Question on loops

5 posts were split to a new topic: Can you help me convert this into list comprehension?

3 posts were split to a new topic: Why do I get ‘None’?

2 posts were split to a new topic: I don’t know what my code does?

4 posts were merged into an existing topic: Why doesn’t iterating with for work while removing items from a list?

4 posts were merged into an existing topic: Why is len(lst) > 0 necessary for solving the list challenge?

def delete_starting_evens(lst):
new_lst=list(lst)
for i in lst:
if i%2==0:
new_lst.pop(0)
else:
break
return new_lst

this is solution with for loop, help to understand why it didnt work before with your for loops.

I was wondering why we can’t use the continue for this problem, I tried it and it seems to be wrong but I don’t know why.

def delete_starting_evens(lst):
for num in lst:
if num % 2 == 0:
continue
print(lst)

Since you’re asked to create a list you’ll want to use list operations like append or something else to manipulate the elements, you’re doing none of that. It also says starting evens, not all even, so you’re ignoring half the condition. Consider how you’d do it manually, what steps does that involve?

What do you think continue does?