hello, good day, does anyone know how to solve this problem? It would help me a lot if you could explain how to do it
-
def ListOfLists(list):
'''
This function receives a list, which can contain elements that are themselves lists and
returns those items separately in a single list.
If the parameter is not of type list, it must return null.
Receive an argument:
list: The list that can contain other lists and is converted to a
list of unique or non-iterable elements.
Ex:
ListOfLists([1,2,['a','b'],[10]]) should return [1,2,'a','b',10]
ListOfLists(108) should return null.
ListOfLists([[1,2,[3]],[4]]) should return [1,2,3,4] -
def ListOfLists(list):
'''
This function receives a list, which can contain elements that are themselves lists and
returns those items separately in a single list.
If the parameter is not of type list, it must return null.
Receive an argument:
list: The list that can contain other lists and is converted to a
list of unique or non-iterable elements.
Ex:
ListOfLists([1,2,['a','b'],[10]]) should return [1,2,'a','b',10]
ListOfLists(108) should return null.
ListOfLists([[1,2,[3]],[4]]) should return [1,2,3,4] -
def ListOfLists(list):
'''
This function receives a list, which can contain elements that are themselves lists and
returns those items separately in a single list.
If the parameter is not of type list, it must return null.
Receive an argument:
list: The list that can contain other lists and is converted to a
list of unique or non-iterable elements.
Ex:
ListOfLists([1,2,['a','b'],[10]]) should return [1,2,'a','b',10]
ListOfLists(108) should return null.
ListOfLists([[1,2,[3]],[4]]) should return [1,2,3,4]A tad late to the party but a recursive approach seems to work.
def Collapse(lst):
result = \[\] for item in lst: if type(item) == list: result.extend(Collapse(item)) else: result.append(item) return result
a = [1, [2, 3, [3.1, 3.2]], 4]
b = Collapse(a)print(a)
print(b)