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

lst //. Rule[a :Rule[Except[_z, 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}}}}

lst = {1 -> a, 2 -> {3 -> c, 4 -> d, 5 -> {6 -> f, 7 -> {8 -> h}}}}

lst //. Rule[a : Except[_z], 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}}}}

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}}}}

deleted 80 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
lst = {1 -> a, 2 -> {3 -> c, 4 -> d, 5 -> {6 -> f, 7 -> {8 -> h}}}}

lst //. Rule[a : Except[_z], 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}}}}

Also

Replace[lst, Rule[a_, b_] :> Rule[z @ a, b], All]

same result

lst = {1 -> a, 2 -> {3 -> c, 4 -> d, 5 -> {6 -> f, 7 -> {8 -> h}}}}

lst //. Rule[a : Except[_z], 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}}}}

Also

Replace[lst, Rule[a_, b_] :> Rule[z @ a, b], All]

same result

lst = {1 -> a, 2 -> {3 -> c, 4 -> d, 5 -> {6 -> f, 7 -> {8 -> h}}}}

lst //. Rule[a : Except[_z], 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}}}}

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

lst = {1 -> a, 2 -> {3 -> c, 4 -> d, 5 -> {6 -> f, 7 -> {8 -> h}}}}

lst //. Rule[a : Except[_z], 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}}}}

Also

Replace[lst, Rule[a_, b_] :> Rule[z @ a, b], All]

same result