1def spread(arg):
2 ret = []
3 for i in arg:
4 if isinstance(i, list):
5 ret.extend(i)
6 else:
7 ret.append(i)
8 return ret
9
10
11def deep_flatten(lst):
12 result = []
13 result.extend(
14 spread(list(map(lambda x: deep_flatten(x) if type(x) == list else x, lst))))
15 return result
16
17
18deep_flatten([1, [2], [[3], 4], 5]) # [1,2,3,4,5]