Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. Here is a partial implementation of a nested list function that returns a brand -new list . def flatten Cobj : Union [int ,
1. Here is a partial implementation of a nested list function that returns a brand -new list . def flatten Cobj : Union [int , List List [int ] "Return a (non - nested list integers in . The integers are returned in the left -to-right t order they appear in . > > > flatten (6) [6] >32 flatten ([1. 2-2. 35. -41) 3. legit ? -1], -2. [1-3, [-5]]]]) , -1, -2. -3. -5 if izingtance (obj , int ) : # Base case omitted return [obj] elge - for sublist in obj : is this night ? Yes ! xtend (flatten (sublist )) return B Our goal is to determine whether the recursive step is correct without fully tracing (or running) this code. Consider the function call flatten ([[0, -1] , -2, [[-3, [-5] , -7]]]). (a) What should flatten [[O. -1], -2. [[-3, [-5], -7]]] return, according to its docstring? / Co, -1, - 2, - 3, - 5, -7] ( assuming the call works ) (b) We'll use the table below to partially trace the call flatten ([[0, -1] , 2. [[-3, [-5], -7]]]). Complete the first two columns of this table , assuming that flatten works properly on each recursive call . Remember that filling out these two columns can be done just using the argument value and flatten 's docstring ; you don't need to worry about the code at all! Note : the input list -2 [[-3, [-5]. -717 has just three sub - nested - lists . sublist flatten (sublist Value of a at the end of the iteration returns
Step 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