Skip to main content
3 of 3
added 1 character in body
kglr
  • 400.5k
  • 18
  • 488
  • 929
lst = {1 -> a, 2 -> {3 -> c, 4 -> d, 5 -> {6 -> f, 7 -> {8 -> h}}}}

lst //.  Rule[Except[_z, a_], b_] :> Rule[z @ a, b]

{z[1] -> a, z[2] -> {z[3] -> c, z[4] -> d, z[5] -> {z[6] -> f, z[7] -> {z[8] -> h}}}}

kglr
  • 400.5k
  • 18
  • 488
  • 929