Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 HEREStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started