Newbie: conventional instead of recursive way

David Brown david at no.westcontrol.spam.com
Thu Dec 19 07:51:12 EST 2002


"Igor Zivkovic" <izivkov1 at jagor.srce.hr> wrote in message
news:atqvnf$j5e$1 at bagan.srce.hr...
> Steve Holden <sholden at holdenweb.com> wrote:
>
> > You can look as long as you like. What makes you feel that recursion is
> > "unconventional"? It's a perfectly valid technique for dealing with
> > recursive data structures, and in fact the most natural way to handle
them.
> > Or is this purely an intellectual exercise? I just don't see what you
hope
> > to gain by avoiding recursion.
>
> I know that the proper way to do it is with recursion. I shouldn't
> have called it unconventional though, sorry. Its just an exercise I can't
> solve. I've read in some tutorial it can be done using loops but it didn't
> give any examples and I can't figure it out on my own. I was hoping
> someone could at least give me a hint.
>

My guess is that a loop is not sufficient here - you are going to have to
use a stack to keep track of where you are.

Think of your list of lists as a tree and draw it out on paper first.






More information about the Python-list mailing list