2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ closely related: 88301, 84757 $\endgroup$ – Kuba Nov 25 '16 at 7:50
  • $\begingroup$ @Kuba Thank you. $\endgroup$ – Deep Nov 25 '16 at 7:52
4
$\begingroup$
{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}

$\endgroup$
  • $\begingroup$ @Zero, my pleasure. Thank you for the accept. $\endgroup$ – kglr Nov 25 '16 at 7:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.