[Python-ideas] Function to return first(or last) true value from list
Oscar Benjamin
oscar.j.benjamin at gmail.com
Fri Feb 21 00:54:25 CET 2014
On 20 February 2014 23:51, Steven D'Aprano <steve at pearwood.info> wrote:
>
> IndexError can also be caught by for-loops, under some circumstances.
> (See the legacy sequence protocol for iteration.)
Only if your code is actually using the legacy sequence protocol:
>>> def f(): yield 2; raise IndexError
...
>>> for x in f():
... print(x)
...
2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in f
IndexError
Oscar
More information about the Python-ideas
mailing list