advanced programming techniques need to change level' valueand just as we need to tell python that we want to change global variables using the global statement (to prevent new local variable from being created rather than the global variable updated)the same applies to variables that we want to change but which belong to an outer scope although it is often best to avoid using global altogetherit is also best to use nonlocal with care def update_indented_list(entry)indented_list append(entry[item]for subentry in sorted(entry[children])update_indented_list(subentryin the algorithm' first stage we build up list of entrieseach (keyitemchildren -tuplein the same order as they are in the original list in the algorithm' second stage we begin with new empty indented list and iterate over the sorted entriescalling update_indented_list(for each one to build up the new indented list the update_indented_list(function is recursive for each top-level entry it adds an item to the indented_listand then calls itself for each of the item' child entries each child is added to the indented_listand then the function calls itself for each child' children--and so on the base case (when the recursion stopsis when an itemor childor child of childand so on has no children of its own python looks for indented_list in the local (inner functionscope and doesn' find itso it then looks in the enclosing scope and finds it there but notice that inside the function we append items to the indented_list even though we have not used nonlocal this works because nonlocal (and globalare concerned with object referencesnot with the objects they refer to in the second version of add_entry(we had to use nonlocal for level because the +operator applied to number rebinds the object reference to new object--what really happens is level level so level is set to refer to new integer object but when we call list append(on the indented_listit modifies the list itself and no rebinding takes placeand therefore nonlocal is not necessary (for the same reasonif we have dictionarylistor other global collectionwe can add or remove items from it without using global statement function and method decorators | decorator is function that takes function or method as its sole argument and returns new function or method that incorporates the decorated function or method with some additional functionality added we have already made use of some predefined decoratorsfor example@property and @classmethod in this subsection we will learn how to create our own function decoratorsand later in this we will see how to create class decorators class decorators