Python has limits on recursion depth. This is a nice language feature because it prevents infinite loops from exploding your runtime, but it can be problematic when dealing with deep data structures and/or graph traversal.
If you see this error. . .
RuntimeError: maximum recursion depth exceeded
. . . don’t freak out. Instead, try increasing the recursion limit. First, find the current limit:
>>> import sys
. . . and then increase the limit:
In my case, I changed the limit from 1000 to 10000, but obviously the appropriate numbers might be different for your problem.