Question: Q2: Deep Map Write a function deep_map_mut that takes a list Ist and a one-argument function func . Ist may be a deep list -

Q2: Deep Map Write a function deep_map_mut that takes a list Ist and a one-argument function func . Ist may be a deep list - that is, it may contain other lists. deep_map_mut replaces each element of Ist and its sublists with the result of calling func on the element. deep_map_mut does not return the mutated list and does not create any new list objects. Hint: type(a) == list will evaluate to True if a is a list. def deep_map_mut(func, Ist): "" "Deeply maps a function over a list, replacing each item in the original list object. Does NOT return the mutated list object. > >> 1 = [1, 2, [3, [4], 5], 6] >>> deep_map_mut (lambda x: x x x, 1) > > > 1 [1, 4, [9, [16], 25], 36] > > > # Check that you're not making new lists > > > s = [3, [1, [4, [1]]]] > > > s1 = s[1] > > > s2 = $1[1] > > > 83 = s2[1] >>> deep_map_mut(lambda x: x + 1, s) > > > s [4, [2, [5, [2]]]] >>> s1 is s[1] True >>> s2 is s1[1] True >>> s3 is s2[1] True "*** YOUR CODE HERE ***"
Q2: Deep Map Write a function_deep_map_mut that takes a list 1st and a one-argument function func. 1st may be a deep list that is, it may contain other lists. deep_map_mut replaces each element of 1st and its sublists with the result of calling func on the element. deep_map_mut does not return the mutated list and does not create any new list objects. Hint: type (a) == list will evaluate to True if a is a list. def deep_map_mut(func, 1st): """Deeply maps a function over a list, replacing each item in the original list object. Does NOT return the mutated list object. >>> 1 = [1, 2, [3, [4], 5], 6] >>> deep_map_mut (1ambda x: x * x, 1) >>> 1 [1, 4, [9, [16], 25], 36] >>> # Check that you're not making new lists >>> s = [3, [1, [4, [1]]]] >>> s1 = s[1] >>> s2 = s1[1] || || || >>> s3 = s2[1] >>> deep_map_mut (lambda x: x + 1, s) >>> S [4, [2, [5, [2]]]] >>> s1 is s[1] True >>> s2 is s1[1] True >>> s3 is s2[1] True "*** YOUR CODE HERE ***"
Step by Step Solution
3.52 Rating (155 Votes )
There are 3 Steps involved in it
To implement the deepmapmut function that deeply applies a given function to all elements in a list ... View full answer
Get step-by-step solutions from verified subject matter experts
