Consider I have the following list with no duplicates. I would like to replace {a,c}
with a number.
lst = {a,b,c,d}
Result I want is {1, b, d}
. This can be in any order.
I have tried the following using SequenceReplace[]
which works only if the sequence I want to replace is in the same order as in lst
.
SequenceReplace[{a, b, c, d}, {b, c} -> 1]
{a,1,d}
SequenceReplace[{a, b, c, d}, {a, c} -> 1]
{a,b,c,d}
Is there a way to get {1, b, d}
?
a, ... , c, ...
in your input list? If so then please update the question with more test cases. $\endgroup$lst /. {a -> 1, c -> Nothing}
$\endgroup$SequenceReplace[lst, {g___, a, x___, c, y___} :> Sequence[g, 1, x, y]]
$\endgroup$SequenceReplace[lst, {a, x___, c} -> Sequence[1, x]]
$\endgroup$