I have the following code:
def flat_list(array):
d=[]
for i in array:
if not isinstance(i, list):
d.append(i)
else:
flat_list(i)
return d
When I call flat_list([1, [2, 2, 2], 4]), I expect it to return unpacked list ([1, 2, 2, 2, 4]). Instead it returns ([1, 4]). Although, if I try (print i) instead of (d.append(i)), it returns unpacked i.
I read an article about recursion, it says return needs to be after base condition.
How do I use kindda (return d.append(i))?