Return returns nothing in recursive function

yellowalienbaby at yellowalienbaby at
Tue Oct 17 22:02:12 CEST 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;

    return GetTreeBranch(path[1:],item[path[0]])

More information about the Python-list mailing list