Are generators in nested functions possible?

David Eppstein eppstein at ics.uci.edu
Thu Jun 20 19:38:22 EDT 2002


In article <mailman.1024614876.11270.python-list at python.org>,
 "Bjorn Pettersen" <BPettersen at NAREX.com> wrote:

> def generateIndexes(length=5, span=1):
>     spanvalues = range(-span, span+1)
>     
>     def genInd(res, length):
>         if length == 1:
>             for val in spanvalues:
>                 yield res + [val]
>         else:
>             for i in range(length):
>                 for val in spanvalues:
>                     genInd(res + [val], length-1)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is a no-op.  Did you mean
                      for x in genInd(res+[val],length-1): return x
?

>     return genInd([], length)

-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list