Python: Maximum recursion depth exceeded

You can increment the stack depth allowed – with this, deeper recursive calls will be possible, like this:

import sys
sys.setrecursionlimit(10000) # 10000 is an example, try with different values

… But I’d advise you to first try to optimize your code, for instance, using iteration instead of recursion.

Leave a Comment