I am trying following recursive function to flatten sent list which may contain sublist items:
def myflatten(slist, outlist=[]):
for sl in slist:
if type(sl) == list:
outlist.append(myflatten(sl, outlist))
else:
outlist.append(sl)
return outlist
print("myflatten list=", myflatten([1,[5,6,7],3,4,[7,8,9]]))
Output:
myflatten list= [1, 5, 6, 7, [...], 3, 4, 7, 8, 9, [...]]
Why am I getting [...]
for every sublist and how can I avoid getting this? Thanks for your help.