Answers for "how to do tail recursion in python"

0

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)
Posted by: Guest on April-28-2022

Python Answers by Framework

Browse Popular Code Answers by Language