Understanding Python bytecode by implementing tail call optimization
blog.fastforwardlabs.com
Understanding Python bytecode by implementing tail call optimization
1–4 of 4 posts
Re: Understanding Python bytecode by implementing tail call optimization
#2This code does not do what the author thinks it does:
def factorial(N, result=1):
if N == 1:
return 1
return factorial(N-1, N*result)Re: Understanding Python bytecode by implementing tail call optimization
#3This code does not do what the author thinks it does: def factorial(N, result=1): if N == 1: return 1 return factorial(N-1, N*result)
No, but the time complexity is the same.
Re: Understanding Python bytecode by implementing tail call optimization
#4This code does not do what the author thinks it does: def factorial(N, result=1): if N == 1: return 1 return factorial(N-1, N*result)
No, but the time complexity is the same.
Okay but if you are going to call the function factorial, why not have it actually calculate a factorial? This would have done the job:
def factorial(N, result=1):
if N == 1:
return result
return factorial(N-1, N*result)
Assuming that you never call it with the result argument.As written, it just looks like the author never ran the code.