✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.
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?
Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!