That’s a smaller amount of loops.
If you’re going to do list slicing, I’d really like to see finding the start location as a separate step (separate line, put result in variable)
And then, if you’re going to use iterators as a strategy of finding the first value - fine.
I'm looking for something more like this for using iterators
def delete_starting_evens(xs): xs = iter(xs) for x in xs: if x % 2 != 0: yield x yield from xs return
Or this, using find and slice
def delete_starting_evens(xs): for i, x in enumerate(xs): if x % 2 != 0: return xs[i:] return 
Or after abstracting out some stuff - if the language doesn't come with the kind of words to describe what's wanted then putting it all in one function may make it a bit difficult to read. Defining the words you want allows for expressing things in nicer ways.
def even(n): return n % 2 == 0 def not_(f): def f_(*args, **kwargs): return not f(*args, **kwargs) return f_ def find(f, xs): for i, x in enumerate(xs): if f(x): return i return i+1 def delete_starting_evens(xs): first_non_even = find(not_(even), xs) return xs[first_non_even:]
But obviously the right word here already exists in dropwhile, to the point where this whole function shouldn't exist at all, dropwhile covers it.
from itertools import dropwhile def even(n): return n % 2 == 0 def delete_starting_evens(xs): return dropwhile(even, xs)