I have a list $\{x,y,z,w,p\}$ and I want to replace $x,y,w$ by $q$. This works
{x,y,z,w,p}/.{x->q, y->q, p->q}
But is there a way to do this concisely? I tried the following, but doesn't work
{x,y,z,w,p}/.{(x || y || p) ->q}
Thanks in advance for any help.
Answer
{x, y, z, w, p} /. Alternatives[x, y, p] -> q (* or *)
{x, y, z, w, p} /. Thread[{x, y, p} -> q]
{q, q, z, w, q}
Comments
Post a Comment