Skip to main content

How to delete an element of a nested list at a specific level and a specific position of this level


(*source*)
sourceStruct =
{{a, {{c1, d}, {e, f}}}, {b, {{c2, h}, {i, k}}}, {m, {{c3, n}, {v,x}}}}
(*target*)

targetStruct = {{a, {{d}, {e, f}}}, {b, {{h}, {i,k}}}, {m, {{n}, {v, x}}}}
(*try 1*)
Apply[Function[x, Delete[x, 1]], Level[sourceStruct, {2}], {1}]
(*result 1*)
{a, {d}, b, {h}, m, {n}}
(*try 2*)
Map[Function[x, Delete[x, 1]], sourceStruct, {3}]
(*result 2*)
{{a, {{d}, {f}}}, {b, {{h}, {k}}}, {m, {{n}, {x}}}}


Comments