Recursion and Generators
Thomas Philips
tkpmep at hotmail.com
Sat Jul 10 14:06:55 EDT 2004
Michael,
I'm totally comfortable with it backing up levels, yielding a new
result each time. It is intuitive to me that at each level it should
yield a list followed by a StopIteration. What is not clear to me is
why it feels an uncontrollable urge to descend through the list of
nested calls to testRecursion one last time after it has come up to
the highest level and yielded [1,2,3,4] StopIteration. If you look at
my original posting, the last three lines are
'__main__'.testRecursion(), line 5: for result in testRecursion(n-1):
'__main__'.testRecursion(), line 5: for result in testRecursion(n-1):
'__main__'.testRecursion(), line 5: for result in testRecursion(n-1):
I'm not sure there is any need for them. Python does not execute the
body of the function the second time around - so why then does it do
this?
Thomas
More information about the Python-list
mailing list