expr = {{{{1, 2}, {1, 3}, {2, 3}}, {3, 2, 1}}, 4};
You can also get the desired result by Map
ping List
on expr
with level spec {-1}
Map[List, expr, {-1}]
{{{{{1}, {2}}, {{1}, {3}}, {{2}, {3}}}, {{3}, {2}, {1}}}, {4}}
Level[expr, {-1}]
{1, 2, 1, 3, 2, 3, 3, 2, 1, 4}
Update:
"as a clarification: I mean all integer elements of a list, not all integers in the list, so in the following example, only 4 should be replaced by {4}":
You can use the replacement rule x_?AtomQ :> {x}
(or x_ /; AtomQ[x] :> {x}
) and level specification 1
in Replace
:
Replace[
{Sin[xx],
xx,
1 + xx,
{{{1, 2}, {1, 3}, {2, 3}}, {3, 2, 1}},
{5},
4},
x_?AtomQ :> {x},
1]
{Sin[xx], {xx}, 1 + xx, {{{1, 2}, {1, 3}, {2, 3}}, {3, 2, 1}}, {5}, {4}}