# Turn {4, 9, {8, {5}}, {2, 3}} into {4, 9, {64, {5}}, {4, 9}} with Map

That's the input I've put

dagny[x_] := x^2;
Map[dagny, {4, 9, {8, {5}}, {2, 3}}, {2}]

Output:

{4, 9, {64, {25}}, {4, 9}}

But this not I want. I wanna {4, 9, {64, {5}}, {4, 9}}

How to Map that at a specific Level?

ClearAll[dagny]
dagny[x : Except[_List]] := x^2;
dagny[x_] := x

Map[dagny, {4, 9, {8, {5}}, {2, 3}}, {2}]

{4, 9, {64, {5}}, {4, 9}}

Do you mean this?

MapAt[dagny, {4, 9, {8, {5}}, {2, 3}}, {{3, 1}, {4}}]
• Nope. Map at a specific level. You're trying to do with the position in a list. What I want here is a a level stuff.
– kile
Jan 29, 2020 at 6:16
• @kile, then you need to modify the function you're mapping: Map[If[! ListQ[#], #^2, #] &, {4, 9, {8, {5}}, {2, 3}}, {2}] Jan 29, 2020 at 6:19
• @J.M. For more generality, I recommend AtomQ. Jan 29, 2020 at 6:28
• @bcegkmqs23 how to achieve that with AtomQ? can u write it in the answer?
– kile
Jan 29, 2020 at 6:34
• @kile, Compare and contrast: Map[If[AtomQ[#], #^2, #] &, {4, 9, {8, {5}}, {2, 3}}, {2}]. Alternatively, you could modify the definition of your function to be mapped: dagny[x_?AtomQ] := x^2; dagny[x_] := x. Jan 29, 2020 at 6:41