Rearranging Lists

Sort[list]sort the elements of list into a standard order
Union[list]sort elements, removing any duplicates
Reverse[list]reverse the order of elements in list
RotateLeft[list,n]rotate the elements of list n places to the left
RotateRight[list,n]rotate n places to the right

Functions for rearranging lists.

This sorts the elements of a list into a standard order. In simple cases like this, the order is alphabetical or numerical.
In[1]:=
Click for copyable input
Out[1]=
This sorts the elements, removing any duplicates.
In[2]:=
Click for copyable input
Out[2]=
This rotates ("shifts") the elements in the list two places to the left.
In[3]:=
Click for copyable input
Out[3]=
You can rotate to the right by giving a negative displacement, or by using RotateRight.
In[4]:=
Click for copyable input
Out[4]=
PadLeft[list,len,x]pad list on the left with x to make it length len
PadRight[list,len,x]pad list on the right

Padding lists.

This pads a list with 's to make it length 10.
In[5]:=
Click for copyable input
Out[5]=
New to Mathematica? Find your learning path »
Have a question? Ask support »