[issue35756] Using `return value` in a generator function skips the returned value on for-loop iteration

Steven D'Aprano report at bugs.python.org
Mon Jan 21 18:38:43 EST 2019


Steven D'Aprano <steve+python at pearwood.info> added the comment:

> I'm off to write an ugly `next()` wrapper then.

Wouldn't it be simpler to re-design the generators to yield the final 
result instead of returning it? To process the final item differently 
from the rest, you just need something like this:

last = next(it)
for x in it:
    process(last)
    last = x
special_handling(last)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35756>
_______________________________________


More information about the Python-bugs-list mailing list