Question: UPDATED: Using Python: Define a function sprout_leaves that, given a tree t , and a list of values vals , returns a tree which is
UPDATED:
Using Python: Define a function sprout_leaves that, given a tree t, and a list of values vals, returns a tree which is the same as t, except that for every leaf that lives at the deepest level in the tree t, it is given new children, one for each of the items in vals.
Example output below:
def sprout_leaves(t, vals): """Sprout new leaves containing the data in vals at each of the deepest leaf in the original tree t and return the resulting tree. >>> t1 = tree(1, [tree(2), tree(3, tree(4))]) >>> print_tree(t1) 1 2 3 4 >>> new1 = sprout_leaves(t1, [5, 6]) >>> print_tree(new1) 1 2 3 4 5 6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
