Recursive generator in Python 3.5

Chris Angelico rosuav at gmail.com
Mon Oct 31 10:21:31 EDT 2016


On Tue, Nov 1, 2016 at 1:03 AM,  <tpqnnd01 at gmail.com> wrote:
> Hi ChrisA,
>
> Thank you so much for sharing this point, I just concern to the point that: normally, I found that the generator (it may be recursive generator also) do not apply the "return" keyword, just the yield only. But when I delete one or both of "return" keyword above, the code do not action. What is the concern here, could you share more experience on that,
>

They do use return, though. Can you show me an example of a generator
that doesn't?

Recursive generators may be slightly tricky, as you can't simply call
them. Most likely you want to 'yield from' the recursive call.

ChrisA



More information about the Python-list mailing list