I prefer other answers (particularly Part
if the application permits it), but I will take this opportunity to mention the undocumented four-argument form of ReplacePart
:
ReplacePart[{1, 2, 3, 4, 5}, {a, b, c}, {{1}, {3}, {5}} , {{1}, {2}, {3}}]
(* {a,2,b,4,c} *)
This syntax says to replace parts 1, 3, and 5 of {1, 2, 3, 4, 5}
with parts 1, 2, and 3 of {a, b, c}
. This syntax has been supported for a very long time, but it is undocumented so I suppose it could disappear some day.
Incidentally, and not relevant to the present question, there is also an undocumented three-argument form:
ReplacePart[{1, 2, 3, 4, 5}, {a, b, c}, {{1}, {3}, {5}}]
(* {{a,b,c},2,{a,b,c},4,{a,b,c}} *)
This form says to replace parts 1, 3, and 5 of {1, 2, 3, 4, 5}
with the value {a, b, c}
.
a
is a list and an element of the last list. p.s. does this work for you:list /. Thread[{1,2,3}->{a,b,c}]
? $\endgroup$ – Kuba♦ Dec 31 '14 at 9:57