[Python-Dev] Tail recursion
Devin
devin at whitebread.org
Thu Nov 27 14:19:04 EST 2003
On Thu, 27 Nov 2003, Andrew Koenig wrote:
> --snip--
> Moreover, I don't know how to write an interative version that is as
> easy to understand as the recursive version.
::Lurk mode off::
import math
def numdigits(n):
assert (n >= 0) and ((n % 1) == 0)
if n < 10:
return 1
return int(math.log10(n)) + 1
(not iterative, but it'll do :)
::Lurk mode on::
--
Devin
devin at whitebread.org
http://www.whitebread.org/
More information about the Python-Dev
mailing list