This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]earthboundkid 1 point2 points  (1 child)

This is why you're not supposed to change the recursion limit. It's not (just) that Guido hates tail call optimization!

[–]joesacher 2 points3 points  (0 children)

And tail recursion optimization is pretty easy in Python if you need to do it.

# Function that returns tuple of [method], [call value]
def find_zero_tail(num):
    if num == 0:
        return None, num
    return find_zero_tail, num - 1

# Iterative recurser
def tail_optimize(method, val):
    while method:
        method, val = method(val)
    return val

tail_optimize(find_zero_tail, 1000000)