Return returns nothing in recursive function
yellowalienbaby at gmail.com
yellowalienbaby at gmail.com
Tue Oct 17 16:02:12 EDT 2006
Fredrik Lundh wrote:
> Matthew Warren wrote:
>
> > I have the following code that implements a simple recursive tree like
> > structure.
> >
> > The trouble is with the GetTreeBranch function, the print statement
> > prints a valid value but the return immediatley afterward doesn't return
> > anything.
>
> hint: how many "return" statements do you see in this piece of code:
>
> else:
> GetTreeBranch(path[1:],item[path[0]])
>
> </F>
(This is Matthew, different google goups account)
aha! Thanks Fredrik. This recursion business always twiddles with my
head ;)
It still took a good stare at the code before I worked it out, then the
little lightbulb moment;
else:
return GetTreeBranch(path[1:],item[path[0]])
More information about the Python-list
mailing list