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 al

 Q2: Pruning Leaves Define a function prune_leaves that given a tree

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 al 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, >>> print_tree(numbers) [tree(4), tree(5)j), tree(6, [tree(7) 2 4 >>>print_tree(prune_leaves(numbers, (3, 4, 6, 7))) HHN YOUR CODE HERE Use Ok to test your code python3 ok -q prune_leaves

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!