Skip to main content
deleted 551 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Replace[erok2 = er;
ok2[[;;3]] = ReplaceAll[er[[;;3]], Association[A -> {a_, b_ }, B -> {c_, d_}, rest___] :>
  Association[A -> {a, Append[Most@d, Last@b]}, B-> {c, Append[Most@b, Last@d]}, rest],rest]];
ok2 Infinity]== ok

{<|A -> {d11, {"1a1", "2a1", "3a1"}}, B -> {d12, {"1b1", "2b1", "3b1"}}, C -> {d13, {"1c1", "2c1", "3c1"}}|>, <|A -> {d21, {"1a2", "2a2", "3a2"}}, B -> {d22, {"1b2", "2b2", "3b2"}}, C -> {d23, {"1c2", "2c2", "3c2"}}|>, <|A -> {d31, {"1a3", "2a3", "3a3"}}, B -> {d32, {"1b3", "2b3", "3b3"}}, C -> {d33, {"1c3", "2c3", "3c3"}}|>, <|A -> {d41, {"1b4", "2b4", "3a4"}}, B -> {d42, {"1a4", "2a4", "3b4"}}, C -> {d43, {"1c4", "2c4", "3c4"}}|>, <|A -> {d51, {"1b5", "2b5", "3a5"}}, B -> {d52, {"1a5", "2a5", "3b5"}}, C -> {d53, {"1c5", "2c5", "3c5"}}|>} True

Replace[er, Association[A -> {a_, b_ }, B -> {c_, d_}, rest___]:>
 Association[A->{a, Append[Most@d, Last@b]}, B->{c, Append[Most@b, Last@d]}, rest],
 Infinity]

{<|A -> {d11, {"1a1", "2a1", "3a1"}}, B -> {d12, {"1b1", "2b1", "3b1"}}, C -> {d13, {"1c1", "2c1", "3c1"}}|>, <|A -> {d21, {"1a2", "2a2", "3a2"}}, B -> {d22, {"1b2", "2b2", "3b2"}}, C -> {d23, {"1c2", "2c2", "3c2"}}|>, <|A -> {d31, {"1a3", "2a3", "3a3"}}, B -> {d32, {"1b3", "2b3", "3b3"}}, C -> {d33, {"1c3", "2c3", "3c3"}}|>, <|A -> {d41, {"1b4", "2b4", "3a4"}}, B -> {d42, {"1a4", "2a4", "3b4"}}, C -> {d43, {"1c4", "2c4", "3c4"}}|>, <|A -> {d51, {"1b5", "2b5", "3a5"}}, B -> {d52, {"1a5", "2a5", "3b5"}}, C -> {d53, {"1c5", "2c5", "3c5"}}|>}

ok2 = er;
ok2[[;;3]] = ReplaceAll[er[[;;3]], Association[A -> {a_, b_ }, B -> {c_, d_}, rest___] :>
  Association[A -> {a, Append[Most@d, Last@b]}, B-> {c, Append[Most@b, Last@d]}, rest]];
ok2 == ok

True

Post Undeleted by kglr
Post Deleted by kglr
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Replace[er, Association[A -> {a_, b_ }, B -> {c_, d_}, rest___]:>
 Association[A->{a, Append[Most@d, Last@b]}, B->{c, Append[Most@b, Last@d]}, rest],
 Infinity]

{<|A -> {d11, {"1a1", "2a1", "3a1"}}, B -> {d12, {"1b1", "2b1", "3b1"}}, C -> {d13, {"1c1", "2c1", "3c1"}}|>, <|A -> {d21, {"1a2", "2a2", "3a2"}}, B -> {d22, {"1b2", "2b2", "3b2"}}, C -> {d23, {"1c2", "2c2", "3c2"}}|>, <|A -> {d31, {"1a3", "2a3", "3a3"}}, B -> {d32, {"1b3", "2b3", "3b3"}}, C -> {d33, {"1c3", "2c3", "3c3"}}|>, <|A -> {d41, {"1b4", "2b4", "3a4"}}, B -> {d42, {"1a4", "2a4", "3b4"}}, C -> {d43, {"1c4", "2c4", "3c4"}}|>, <|A -> {d51, {"1b5", "2b5", "3a5"}}, B -> {d52, {"1a5", "2a5", "3b5"}}, C -> {d53, {"1c5", "2c5", "3c5"}}|>}