Skip to content

ReplacePart ​

expr with the operand at position i replaced by new — Wolfram 1-based positions, negative counting from the end.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageReplacePart✓
ReplacePart(expr, i -> new)expr with its ith operand replaced (1-based; i < 0 counts from the end)
ReplacePart(expr, {i, j, …} -> new)like the scalar form, drilling into nested operands along the given path
ReplacePart(expr, {rule1, rule2, …})applies every rule, each position resolved against the RESULT of the earlier ones
Typed signatures
TypePackageApplies
(any, expression<Rule> | list<expression<Rule>>) -> anycombinatoricsalways

Domain: Collections

Examples

Basic #
live ↗
InReplacePart([a,b,c],Rule(2,z))\mathrm{ReplacePart}(\bigl\lbrack a, b, c\bigr\rbrack, \mathrm{Rule}(2, z))Out[a,z,c]\bigl\lbrack a, z, c\bigr\rbrack
Scope #
live ↗
InReplacePart([a,b,c],Rule(−1,z))\mathrm{ReplacePart}(\bigl\lbrack a, b, c\bigr\rbrack, \mathrm{Rule}(-1, z))Out[a,b,z]\bigl\lbrack a, b, z\bigr\rbrack
live ↗
InReplacePart([a,b,c],[Rule(1,x),Rule(3,y)])\mathrm{ReplacePart}(\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack\mathrm{Rule}(1, x), \mathrm{Rule}(3, y)\bigr\rbrack)Out[x,b,y]\bigl\lbrack x, b, y\bigr\rbrack
live ↗
InReplacePart([[a,b],c],Rule([1,2],z))\mathrm{ReplacePart}(\bigl\lbrack\bigl\lbrack a, b\bigr\rbrack, c\bigr\rbrack, \mathrm{Rule}(\bigl\lbrack1, 2\bigr\rbrack, z))Out[[a,z],c]\bigl\lbrack\bigl\lbrack a, z\bigr\rbrack, c\bigr\rbrack
About
Examples4
Checked againstWolfram Language 4 agree
CrosswalkWolfram Language

See also: Replace, Level