Just started toying around with Python so please bear with me :)
Assume the following list which contains nested lists:
[[[[[1, 3, 4, 5]], [1, 3, 8]]
More efficient than recursion:
result = [] while lst: l = lst.pop(0) if type(l[0]) == list: lst += [sublst for sublst in l if sublst] # skip empty lists [] else: result.insert(0, l)