Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago