advanced programming techniques one common use case for local functions is when we want to use recursion in these casesthe enclosing function is calledsets things upand then makes the first call to local recursive function recursive functions (or methodsare ones that call themselves structurallyall directly recursive functions can be seen as having two casesthe base case and the recursive case the base case is used to stop the recursion recursive functions can be computationally expensive because for every recursive call another stack frame is usedhoweversome algorithms are most naturally expressed using recursion most python implementations have fixed limit to how many recursive calls can be made the limit is returned by sys getrecursionlimit(and can be changed by sys setrecursionlimit()although increasing the limit is most often sign that the algorithm being used is inappropriate or that the implementation has bug the classic example of recursive function is one that is used to calculate factorials for examplefactorial( will calculate and return that is def factorial( )if < return return factorial( this is not an efficient solutionbut it does show the two fundamental features of recursive functions if the given numberxis or less is returned and no recursion occurs--this is the base case but if is greater than the value returned is factorial( )and this is the recursive case because here the factorial function calls itself the function is guaranteed to terminate because if the initial is less than or equal to the base case will be used and the function will finish immediatelyand if is greater than each recursive call will be on number one less than before and so will eventually be to see both local functions and recursive functions in meaningful context we will study the indented_list_sort(function from module file indentedlist py this function takes list of strings that use indentation to create hierarchyand string that holds one level of indentand returns list with the same strings but where all the strings are sorted in case-insensitive alphabetical orderwith indented items sorted under their parent itemrecursivelyas the before and after lists shown in figure illustrate given the before listthe after list is produced by this callafter indentedlist indented_list_sort(beforethe default indent value is four spacesthe same as the indent used in the before listso we did not need to set it explicitly python' math module provides much more efficient math factorial(function