There is a list of UndirectedEdge
:
list = {1 <-> 2, 2 <-> 3, 4 <-> 5}
How to change it to:
{101 <-> 102, 102 <-> 103, 104 <-> 105}
?
I tried :
list /. UndirectedEdge[x_, y_] /; x :> x + 100;
list /. x_ <-> y_ /; x + 100 <-> y + 100;
list /. x_UndirectedEdge /; First[x] <-> Last[x]
list /. x_UndirectedEdge /; x :> First[x] <-> Last[x];
but they are not working correctly.
x_ \[UndirectedEdge] y_
, and the correct replacementx + 100 \[UndirectedEdge] y + 100
the only minor mistake is that you usedCondition
,\;
, which should beRuleDelayed
,:>
. Therefore try:list /. x_ \[UndirectedEdge] y_ :> x + 100 \[UndirectedEdge] y + 100;
$\endgroup$list /. x_Integer :> 100 + x
$\endgroup$