[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Recursive generator in Python 3.5
From:       Gregory Ewing <greg.ewing () canterbury ! ac ! nz>
Date:       2016-10-31 22:25:33
Message-ID: e7pumvFptduU1 () mid ! individual ! net
[Download RAW message or body]

tpqnnd01@gmail.com wrote:

> def fg(args):
>   if not args:
>     yield ""
>     return
>   for i in args[0]:
>     for tmp in fg(args[1:]):
>       yield i + tmp
>   return

The final return is redundant, since there is an implicit return
at the end, just like an ordinary function. The other one is just
performing an early exit from the iteration. You could write it
without any returns like this:

def fg(args):
   if not args:
     yield ""
   else:
     for i in args[0]:
       for tmp in fg(args[1:]):
         yield i + tmp

> this is the Tower of Hanoi with  recursive generator but it do
 > not have the 'return' here

-- 
Greg
-- 
https://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic