FOR statement

Ant antroy at gmail.com
Sat Oct 21 03:50:34 EDT 2006


Jordan Greenberg wrote:
...
> >>> def printreverse(lst):
> 	if lst:
> 		printreverse(lst[1:])
> 		print lst[:1][0]

Convoluted way of writing "print lst[0]" !

> >>> printreverse([1,2,3,4])
>
> No good reason at all to do it this way. But recursion is fun.

But there's a good reason not to. Try:

printreverse(range(1000))

Recursion has a maximum depth (of 1000 by default) in Python.




More information about the Python-list mailing list