next((x for x in mylist if x))
And, in Python 3, thanks to filter returning an iterator, you’d do this:
next(filter(bool,mylist))
It still is pretty common. Common enough to make it aggravating to write a function to do that nearly every time. My idea is to add first and last functions that do just that.
Stuff that’s open to lots of debate:
Names. They’re not very creative; I know.
Builtin or itertools. I’m personally leaning towards the latter at the moment.
Implementing it in itertools would be simple:
def first(it):
return next(filter(bool,it))
def last(it):
return next(reversed(filter(bool,it)))