2 ms·
> raising an exception to break iteration You don't have to. def mygen(): yield 1 yield 2 return print "never been here"
by est 13y ago
> raising an exception to break iteration
You don't have to.
def mygen():
yield 1
yield 2
return
print "never been here"
>>> list(mygen())
[1, 2]
I agree some parts of python are hackish though. Maybe because of legacy reasons. And py3k didn't fix all of them