WolframLang: Add Element to List
Functions that operate on list usually do not modify the list, nor a variable holding the list. They return a new list. This is true for vast majority of WolframLang functions.
If you want to modify the variable that hold a list, you assign it back, example:
list = f[ list, etc ]
Function whose name end in βToβ,
(e.g. AppendTo
)
modifies the variable. (the argument must be a variable.)
Insert
Insert[list, elem, n]
-
Insert an element at n
same as
Insert[list, elem, {n}]
Insert[ {3, 4}, x, 2 ] === {3, x, 4}
Insert[list, elem, {i, j, k}]
-
- Insert an element at Position
{i, j, k}
- Return a new list. (Does not modify the list.)
Insert[ {3, 4}, x, {2} ] === {3, x, 4} Insert[ {3, {4}}, x, {2,1} ] === {3, {x, 4}}
- Insert an element at Position
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}}
Append, Prepend
WolframLang List Operations
- WolframLang: List Operations
- WolframLang: Get Parts of List
- WolframLang: Add Element to List
- WolframLang: Delete Element in List
- WolframLang: Change Element in List
- WolframLang: Check Item Existence in List
- WolframLang: List Order Functions
- WolframLang: List Restructure Functions
- WolframLang: List Combinatorics
- WolframLang: List Join, Union, Intersection, Difference