Understanding how is a function evaluated using recursion

Peter Cacioppi peter.cacioppi at gmail.com
Sat Sep 28 16:24:28 EDT 2013


On Thursday, September 26, 2013 7:23:47 AM UTC-7, Neil Cerutti wrote:
> On 2013-09-26, Neil Cerutti <neilc at norwich.edu> wrote:
> 
> > def flatten(seq):
> 
> >
> 
> > [1] http://en.wiktionary.org/wiki/bikeshed
> 
> 
> 
> In that spirit, it occurs to me that given current Python
> 
> nomenclature, 'flattened' would be a better name.
> 
> 
> 
> -- 
> 
> Neil Cerutti


The example presented here is simple enough for someone who is confident with recursion and somewhat new to Python. So perhaps a refresher on recursion would help.


The way to grok recursion for the first time is (a) to read some general info about it (Wikipedia has some decent stuff here, but there are many other sources) and (b) find a simple recursion example and play around with it in the debugger.

Python has some decent debugger solutions - I like using ipdb with iPython.

The factorial function is a good one to play around with if you're new to recursion. The Fibonacci sequence is also good. Find a .py example, or, better yet, write your own based on psuedo code.

If you're a recursion expert already, then I don't know what to tell you other than Python seems to have implemented recursion faithfully and there are no gotchas that I can see.



More information about the Python-list mailing list