Are generators in nested functions possible?
Bjorn Pettersen
BPettersen at NAREX.com
Thu Jun 20 19:51:14 EDT 2002
> From: David Eppstein [mailto:eppstein at ics.uci.edu]
>
> 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 ?
Thanks! I knew it had to be something simple (got your other post about
using yield instead of return).
-- bjorn
More information about the Python-list
mailing list