So I solved this with a solution I found online:
def flatlist(array):
if array == []:
return array
if isinstance(array[0], list):
return flatlist(array[0]) + flatlist(array[1:])
return array[:1] + flatlist(array[1:])
But I originally had the following code which from my research should have worked, yet it would only append integers and not recursively call the function on a nested list. What am I missing?
def flat_list(array):
flat = []
for a in array:
if type(a) is list:
flat_list(a)
else:
flat.append(a)
return flat
Created at: April 23, 2019, 11:19 p.m.; Updated at: April 24, 2019, 11:49 a.m.
The question is resolved.