better yetfor loops iterate for us automaticallymaking recursion largely extraneous in many cases (andin all likelihoodless efficient in terms of memory space and execution time) [ sum for in lsum + sum with looping statementswe don' require fresh copy of local scope on the call stack for each iterationand we avoid the speed costs associated with function calls in general (stay tuned for ' timer case study for ways to compare the execution times of alternatives like these handling arbitrary structures on the other handrecursion--or equivalent explicit stack-based algorithms we'll meet shortly--can be required to traverse arbitrarily shaped structures as simple example of recursion' role in this contextconsider the task of computing the sum of all the numbers in nested sublists structure like this[ [ [ ] ] [ ]arbitrarily nested sublists simple looping statements won' work here because this is not linear iteration nested looping statements do not suffice eitherbecause the sublists may be nested to arbitrary depth and in an arbitrary shape--there' no way to know how many nested loops to code to handle all cases insteadthe following code accommodates such general nesting by using recursion to visit sublists along the wayfile sumtree py def sumtree( )tot for in lif not isinstance(xlist)tot + elsetot +sumtree(xreturn tot for each item at this level add numbers directly recur for sublists [ [ [ ] ] [ ]print(sumtree( )arbitrary nesting prints pathological cases print(sumtree([ [ [ [ [ ]]]]])print(sumtree([[[[[ ] ] ] ] ])prints (right-heavyprints (left-heavy advanced function topics