Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to do tail recursion in python

from tail_recurse import *

@tail_call
def fact(n):
    def tail_func(n, res):
        if n == 1:
            return res
        else:
            return tail_func(n - 1, n * res)

    return tail_func(n, 1)
 
PREVIOUS NEXT
Tagged: #tail #recursion #python
ADD COMMENT
Topic
Name
9+2 =