I have nested lists wherein there are a lot of waste levels which looks like
l = {{{{{{2, 2}}, 3}, 2, {{2, 33}}, 4, 5}}};
I would like to reduce it to somthing like
l = {{{2, 2}, 3}, 2, {2, 33}, 4, 5};
I made the function which remove waste levels on the top level:
l = {{{{{{2, 2}}, 3}, 2, {{2, 33}}, 4, 5}}};
strip = Function[{list},
If[(Head[list] === List) && (Length[list] > 0),
If[Flatten[list, 1] === list[[1]],
s = strip[list[[1]]],
s = list],
s = list];
s];
strip[l]
To do it at any depth I tried to do Map[strip[l]]
without success.
How I can to apply my function to all levels? Also, I guess there more appropriate way to solve my problem.