Question: for python 3 Problem A: Flatten List (10 points) As you know, lists in Python can contain objects of any kind. It is possible, therefore,

for python 3

Problem A: Flatten List (10 points) As you know, lists in Python can contain objects of any kind. It is possible, therefore, to have a list which contains another lista nested list. You may even have a list like [[[[[1]],[],4],2,5,[3]]] where the elements are nested multiple times, and in no sensible order.

Your assignment is to write a recursive function, flattenList(alist), that returns a flattened version of any given list. That is, all elements (not including lists) of the given list should be in the final, non-nested list in their original order. For example, if the above list was the input, your function should return [1, 4, 2, 5, 3] Your program does not need a main.

You do not need to prompt for input from the user; just write the function, and all testing on our part will be done by calling your function with parameters we have defined. Of course, you may test your program however you like. Constraints:

The name of your function must be flattenList (this makes testing easier for us)

Your function must be pure; i.e., it should not mutate the input object at all, and may not use print statements

Your function must be recursive (loops are not allowed)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!