How to | Perform Operations on Lists

Lists are central constructs in Mathematica that are used to represent collections, arrays, sets, and sequences of all kinds. Well over a thousand built-in functions throughout Mathematica operate directly on lists, making them a powerful vehicle for interoperability.

Set up a list of 5 random integers between 0 and 10 (stored as ):

In[45]:=
Click for copyable input
Out[45]=

Use Max to get the largest element of :

In[46]:=
Click for copyable input
Out[46]=

Set up a 4×3 matrix of random integers between 0 and 10:

In[47]:=
Click for copyable input
Out[47]=

Use Map to apply Max to each element of at the top level:

In[48]:=
Click for copyable input
Out[48]=
    

You can add two lists of the same length element by element:

In[49]:=
Click for copyable input
Out[49]=

Add the scalar to each element of a list:

In[50]:=
Click for copyable input
Out[50]=

Multiply each element in the list by the scalar :

In[51]:=
Click for copyable input
Out[51]=
    

Set up a list of 5 integers:

In[43]:=
Click for copyable input
Out[43]=

Prepend the element at the beginning of the list :

In[44]:=
Click for copyable input
Out[44]=

Append at the end of :

In[45]:=
Click for copyable input
Out[45]=

Insert the element at position 3 of the list :

In[46]:=
Click for copyable input
Out[46]=

Delete the element at position 3 in :

In[47]:=
Click for copyable input
Out[47]=

Replace the element at position 3 in with a new element :

In[48]:=
Click for copyable input
Out[48]=

Interleave between the entries of :

In[49]:=
Click for copyable input
Out[49]=
New to Mathematica? Find your learning path »
Have a question? Ask support »