1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
|
def flatten(lst):
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst), [] )
>>> liste= [3,4,[[5]]]
>>> test= [[[1, 2, liste], (6, [7]), 8], 9, False]
>>> flatten(test)
[1, 2, 3, 4, 5, (6, [7]), 8, 9, False]
>>> test
[[[1, 2, [3, 4, [[5]]]], (6, [7]), 8], 9, False]
>>> liste
[3, 4, [[5]]]
|