Question: Python Question Q2: Pruning Leaves Define a function prune_leaves that given a tree t and a tuple of values vals, produces a version of t
Python Question

Q2: Pruning Leaves Define a function prune_leaves that given a tree t and a tuple of values vals, produces a version of t with all its leaves that are in vals removed. Do not attempt to try to remove non-leaf nodes and do not remove leaves that do not match any of the items in vals. Return None if pruning the tree results in there being no nodes left in the tree def prune leaves (t, vals): " "Return a modified copy of t with all leaves that have a label that appears in vals removed. Return None if the entire tree is pruned away >>> t tree ( 2 ) >>print (prune_leaves (t, (1, 2))) None >numbers-tree(1,[tree (2),tree (3, [tree (4),tree (5)]), tree (6, [tree (7)])]) >>> print_tree (numbers) 2 >>> print_tree(prune_leaves (numbers, (3, 4, 6, 7))) 2 YOUR CODE HERE
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
