Recursive generator in Python 3.5

Chris Angelico rosuav at gmail.com
Mon Oct 31 11:02:30 EDT 2016


On Tue, Nov 1, 2016 at 1:50 AM,  <tpqnnd01 at gmail.com> wrote:
>
> Please see the exampl I just got it below, this is the Tower of Hanoi with recursive generator but it do not have the 'return' here, do you have the advice for this term:
>
> def A001511():
>     yield 1
>     b=1
>     for x in A001511():
>         yield x+1
>         yield 1
>
>
> trial=A001511()
> for i in range(10):
>     a=next(trial)
>     print(a)

As soon as you get to the end of the function, it returns.

When you iterate over a generator, you run it to completion, taking
all the values it yields.

ChrisA



More information about the Python-list mailing list