flat_list=[]
def rec_flatten(alist):
for i in alist:
if i == None:
return
if type(i)==list:
flat_list.append(rec_flatten(i))
else:
flat_list.append(i)
return
rec_flatten(['a',['b','c'],'d',['e','f',['g','h']]])
print(flat_list)
Gives:
['a', 'b', 'c', None, 'd', 'e', 'f', 'g', 'h', None, None]
How do I change this function so that the None returns aren't added to the list?