[('nonmetals''nonmetals'[('hydrogen'hydrogen'[])('carbon'carbon'[])('nitrogen'nitrogen'[])('oxygen'oxygen'[])])('inner transitionals''inner transitionals'[('lanthanides'lanthanides'[('cerium'cerium'[])('europium'europium'[])])('actinides'actinides'[('uranium'uranium'[])('curium'curium'[])('plutonium'plutonium'[])])])('alkali metals''alkali metals'[('lithium'lithium'[])('sodium'sodium'[])('potassium'potassium'[])])the output was produced using the pprint ("pretty print"module' pprint pprint(function notice that the entries list has only three items (all of which are -tuples)and that each -tuple' last element is list of child -tuples (or is an empty listthe add_entry(function is both local function and recursive function like all recursive functionsit has base case (in this functionwhen the level is that ends the recursionand recursive case the function could be written in slightly different waydef add_entry(keyitemchildren)nonlocal level if level = children append((keyitem[])elselevel - add_entry(keyitemchildren[- ][children]hereinstead of passing level as parameterwe use nonlocal statement to access variable in an outer enclosing scope if we did not change level inside the function we would not need the nonlocal statement--in such situationpython would not find it in the local (inner functionscopeand would look at the enclosing scope and find it there but in this version of add_entry(we