FOR statement

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Sat Oct 21 04:31:55 EDT 2006


Theerasak Photha:
> I guess Python isn't tail-recursive then?

Right.


> Well, algorithms seem to be more naturally expressed iteratively in
> Python, and to be fair, most uses of recursion you see in e.g., Scheme
> textbooks are really just grandstanding in the real world.

Still, some algorithms enjoy some recursivity anyway, like some graph
or tree exploration, structure flattening, and so on, for them I
sometimes use recursivity in Python too. The maximum recursivity level
can be increased too. Stackeless Python probably helps in recursive
code too. Psyco too. New Python versions have some optimizations for
function calling and so on, than help.
Often iterative code is the simpler solution, but sometimes recursivity
is the simpler solution, so a "better" (faster, leaner) recursivity
management may be good for a hi-level language like Python. So maybe in
future people here will improve its recursivity use some more.

Bye,
bearophile




More information about the Python-list mailing list