Need a recursion lesson

Magnus L. Hetland mlh at vier.idi.ntnu.no
Wed Dec 22 09:22:04 EST 1999


"Eide" <nickliz at t-online.de> writes:

> Hello,
> I would like to do a search for file types, and I figure a good way to do it
> would be with recursion...  compare a sliced 'file[:-6]' of each item in
> list from a directory.  And if there is another directory in that list to do
> a listdir on it and .... My head is spinning already.
> I have no clue what I'm doing. Does anyone have any pointers to about how to
> walk through something like this? Any help would be a lot.

I see you have gotten an answer to your problem at hand - but it seems
you also wanted some pointers on recursion in general, or am  I
mistaken?

Most programming books have some explanations on the subject - I would
just like to offer a tip that I have used in explaining recursion to
students... I think it can be helpful to envision each method call as
some sort of "agent" (a little goblin or whatever <wink>) receiving a
request of some sort. This agent, in turn, may ask other agents for
help in the matter, waiting for their response etc. The function
definition describes the behaviour of all of them... At least what
seems to me as potentially confusing is the notion that the function
calls "itself". Envisioning it as calling another function (with the
same definition) might be clarifying...

Oh, well... Rambling as usual. :)

> 
> Nick
> 
> 

--

  Magnus
  Lie
  Hetland



More information about the Python-list mailing list