I have a big list which in principle can be described as this more compact list :
list1 = {{e, {{a, 0.1}, {b, 0.3}, {c, 0.5}, {d, 0.7}},
f, {{a, 0.2}, {b, 0.4}, {c, 0.6}, {d, 0.8}}, g, h, i}};
I am interested in rewriting to the following :
{{e, {"abcd", 0.1, 0.3, 0.5, 0.7}, f, {"abcd", 0.2, 0.4, 0.6, 0.8}, g,
h, i}}
which works well when applying this simple rule:
list1 /. {{a, x1_}, {b, x2_}, {c, x3_}, {d, x4_}} -> {"abcd", x1, x2,
x3, x4}
However when the affected sublists {a,x1} to {d,x4} are not on the same depth, I have difficulties constructing a rule that works. So for instance:
list2 = {{e, {a, 0.1}, {b, 0.3}, {c, 0.5}, {d, 0.7},
f, {{a, 0.2}, {b, 0.4}, {c, 0.6}, {d, 0.8}}, g, h, i}}
does not give the desired result.
So my questions are: 1. Is there a way to ReplaceAll independent of depth? 2. Is there a more elegant method that does the job?


list2 /. PatternSequence[{a, x1_}, {b, x2_}, {c, x3_}, {d, x4_}] :> {"abcd", x1, x2, x3, x4}(It of course doesn't.) – Mr.Wizard Aug 14 '14 at 17:52... when it really could be O(n), if we had better ways of describing and using sequence-based patterns. What we really need is one or two functions with the same semantics as the String* functions ...is exactly what I am talking about, though on reflection I agree thatPatternSequencelikely plays no role in that. I have actually converted expressions into strings simply for the sequence handling, which seems indicative of a hole in the language at present. – Mr.Wizard Aug 14 '14 at 18:57