# this is a python programming

I Have Your answer to this problem in thequot;Millen. pyquot; like !`
Recall that amp; Python list can contain any type of element , even another list. As a result, we can have list of lists, licks of lists
of lists , and so on . with ever- increasing levels of nesting . This problem intends to put a stop In that sort of nonsense .
Complete the Flatten ! ! function , which takes a single list as its argument . The function examines its list argument and*
RECURSIVELY’ generates (and returns ; a new single- level ( non – nested; list that contains every element from the original
list, in the same onder it appeared in that list . For example , the list 12. 14. 61 . \$1 contains a list as one of its elements !
Flatten ! ! will process this list and return the new single- level list 12. 4 6. \$1. where the inner list has been eliminated!
and its elements have replaced the original sublist
The possible recursive strategy resembles the following*
. If the current list is an empty list . simply return an empty list ( This is your base case )
. Otherwise !
. If the first element of the current list is a list, return the result of flattening that list plus the result of flattening the
reminder of the list . ( This is your first recursive case )*
. Otherwise , return a list containing just the first element plus the result of flattening the remainder of the list . ( This
Is your second recursive case )
Hint : Python has a special function named is instance !’ that can be extremely helpful here. isinstance !’ lakes
two arguments . amp; value to examine , and the name of a Python type (in this case . List) . It reams True or False
depending on whether the first argument belongs In the specified type . For example , the function call is instance ( 12 .
int ) returns True . while the function call amp; singtance ! ‘ 3 . 14 ‘, Float ; returns False.
Function Lull
Heturn Value
Flatten ! ! ! !
Flatten \$ 1 21 1
121
\Flatteni13 . 5 . 1 . 01 1
\13 . 6 . 1 . 01
\Flatten ! ! 151 1 1\
Flatten 1 1 1 . 3 . 5 . 171 . 5 . 11 1 1
[ 151
\11 . 3 . 5 . 7 . 5 . 111
flatten ! ! !\$1 . 32 . 36 . 55 , 193. 541 . 50 .
15 . 32 , 36 . 55, 53 . 59 . 98 , BB ]
leei’ll
Flatten ! ! ! !131 1 1 1 1\
131
Flatten \$ 165 , 152 . 411 . 17. 124. 351 . 931 .
165 , 52 . 41 . 7, 14. 35, 93, 73, 33 . 5^ ^ ^` .`
73 . 33 . 91. 14. 163, 24 . 1 127 , 381 . 178 .
\$3 , 24 , 27 , 89 , 78 , 75, 13, 31 , 841
75 . 131 . 311 . 841 1 1\
Python Programming