Hi all, I’m just beginning to learn about patterns and rules. How would I have to write the following rule, so that the enclosing list does not get processed by it? (Meaning: How do I get rid of the first “x”?)
{1, 2, 3, a, b, c} /. {i_Integer -> i*2, s_Symbol -> x} x[2, 4, 6, x, x, x]
Thank you very much!
{1, 2, 3, a, b, c} /. {i_Integer → i*2, s_Symbol /; Head[s] != List → x}
Hmm, that doesn’t work, I’m afraid.
Try
Replace[{1, 2, 3, a, b, c}, {i_Integer -> i*2, s_ -> x}, {1}]
which gives me
{2,4,6,x,x,x}
That did the trick. Thank you!