Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions