Im trying to write a function that get a list, and return a flatten one, for example
a=[1,2,[3,5,(2,3)]]
print(flat(a))
[1,2,3,5,(2,3)]
I wrote this :
def flat(lst,res=[]):
if len(lst)==0:
return res
else:
for element in lst:
if isinstance(element,list):
res.append(flat(element))
res.append(element)
return res
but my output is :
[1, 2, 3, 5, (2, 3), [...], [3, 5, (2, 3)]]
can you help me spot the mistake ?