the below code snippet flattens the nested list and the elements to the new list recursively but couldn't append all the elements to the list.
expected output : [1,2,4,5,6,7,5,8]
my output : [1,2,8]
def foo(l):
result = []
for i in l:
if type(i)==list:
foo(i)
else:
result.append(i)
return result
input_list = [1,2,[4,5,[6,7],5],8]
print (foo(input_list))