logo

Crowdly

Browser

Add to Chrome

The following incomplete Python code is intended to flatten a nested list. A nes...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

The following incomplete Python code is intended to flatten a nested list. A nested list is a list which can have lists as elements (and each such list element can be a nested list, recursively). A flattened list is a list that has no list as an element. When flattening a nested list, the flattened list must contain all the non-list elements in the original nested list. In the code, the input parameter is the original nested list and the function should return the flattened list.

def FlattenList(mylist):

retlist = []

if (len(mylist) == 0):

return []

elif (type(mylist[0]) is list):

......(A).....

else:

retlist.append(mylist[0])

......(B)......

return retlist

What will be the most suitable parts to fill the blanks A and B, respectively, so that the code will work correctly?

50%
0%
0%
More questions like this

Want instant access to all verified answers on online.uom.lk?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome