This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
 MATHEMATICA TUTORIAL Related Tutorials »|More About »| Functions »

# Adding, Removing, and Modifying List Elements

 Prepend[list,element] add element at the beginning of list Append[list,element] add element at the end of list Insert[list,element,i] insert element at position i in list Insert[list,element,-i] insert at position i counting from the end of list Riffle[list,element] interleave element between the entries of list Delete[list,i] delete the element at position i in list ReplacePart[list,i->new] replace the element at position i in list with new ReplacePart[list,{i,j}->new] replace with new

Functions for manipulating elements in explicit lists.

This gives a list with prepended.
 Out[1]=
This inserts so that it becomes element number 2.
 Out[2]=
This interleaves between the entries of the list.
 Out[3]=
This replaces the third element in the list with .
 Out[4]=
This replaces the 1, 2 element in a 2×2 matrix.
 Out[5]=
Functions like ReplacePart take explicit lists and give you new lists. Sometimes, however, you may want to modify a list "in place", without explicitly generating a new list.
 v={e1,e2,...} assign a variable to be a list v[[i]]=new assign a new value to the i element

Resetting list elements.

This defines to be a list.
 Out[6]=
This sets the third element to be .
 Out[7]=
Now has been changed.
 Out[8]=
 m[[i,j]]=new replace the element of a matrix m[[i]]=new replace the i row m[[All,i]]=new replace the i column

Resetting pieces of matrices.

This defines to be a matrix.
 Out[9]=
This sets the first column of the matrix.
 Out[10]=
This sets every element in the first column to be .
 Out[11]=