and repeats in later examples listed in the next section some programs may also need to record complete paths for each state followed so they can report solutions when finished in such caseseach item in the nonrecursive scheme' stack or queue may be full path list that suffices for record of states visitedand contains the next item to explore at either end also note that standard python limits the depth of its runtime call stack--crucial to recursive call programs--to trap infinite recursion errors to expand ituse the sys modulesys getrecursionlimit( sys setrecursionlimit( help(sys setrecursionlimit calls deep default allow deeper nesting read more about it the maximum allowed setting can vary per platform this isn' required for programs that use stacks or queues to avoid recursive calls and gain more control over the traversal process more recursion examples although this section' example is artificialit is representative of larger class of programsinheritance trees and module import chainsfor examplecan exhibit similarly general structuresand computing structures such as permutations can require arbitrarily many nested loops in factwe will use recursion again in such roles in more realistic examples later in this bookin ' permute pyto shuffle arbitrary sequences in ' reloadall pyto traverse import chains in ' classtree pyto traverse class inheritance trees in ' lister pyto traverse class inheritance trees again in appendix ' solutions to two exercises at the end of this part of the bookcountdowns and factorials the second and third of these will also detect states already visited to avoid cycles and repeats although simple loops should generally be preferred to recursion for linear iterations on the grounds of simplicity and efficiencywe'll find that recursion is essential in scenarios like those in these later examples moreoveryou sometimes need to be aware of the potential of unintended recursion in your programs as you'll also see later in the booksome operator overloading methods in classes such as __setattr__ and __getattribute__ and even __repr__ have the potential to recursively loop if used incorrectly recursion is powerful toolbut it tends to be best when both understood and expectedrecursive functions