Wolfram: List. Add Element

By Xah Lee. Date: . Last updated: .

Insert

Insert[list, elem, n]
  • Insert an element at index n.
  • If n is negative, count from right.
  • Return a new list.

Insert

Insert[ {3, 4}, x, 2 ]
(* {3, x, 4} *)
Insert[ {3, 4}, x, -1 ]
(* {3, 4, x} *)
Insert[list, elem, {i, j, k}]
  • Insert an element at Position {i, j, k}
Insert[ {3, {4}}, x, {2,1} ]
(* {3, {x, 4}} *)
Insert[list, elem, {pos1, pos2, etc }]

insert an element at several positions

Insert[ {{1,0}, {2,0}, {3,0}}, x, {{2}, {3,1}} ]
(* {{1, 0}, x, {2, 0}, {x, 3, 0}} *)

Prepend, Append

Prepend

Add to beginning. Return a new expr.

Prepend

Prepend[ List[ 3, 4 ], 5 ]
(* {5, 3, 4} *)
Append[expr, new]

return a new expr with new item added at end.

Append

Append[ List[ 3, 4 ], 5 ]
(* {3, 4, 5} *)

PrependTo, AppendTo

PrependTo[x, elem]

Same as x=Prepend[x, elem]

PrependTo

AppendTo[x, elem]

Same as x=Append[x, elem]

AppendTo

WolframLang List Operations