Skip to main content
4 of 5
replaced http://stackoverflow.com/ with https://stackoverflow.com/

Recursion. It would make the code smaller, easier to understand, way easier to implement as well. What you are trying to do is one of the tasks recursion is very good at.

How can I build a recursive function in python?

Basics of Recursion in Python