This is documentation for Mathematica 4, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
Wolfram Research, Inc.

Advanced Topic: Lists as SetsGrouping Together Elements of Lists

1.8.9 Rearranging Lists

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]:= Sort[{b, a, c, a, b}]

Out[1]=

This sorts the elements, removing any duplicates.

In[2]:= Union[{b, a, c, a, b}]

Out[2]=

This reverses the list.

In[3]:= Reverse[{a, b, c, d}]

Out[3]=

This rotates ("shifts") the elements in the list two places to the left.

In[4]:= RotateLeft[{a, b, c, d, e}, 2]

Out[4]=

You can rotate to the right by giving a negative displacement, or by using RotateRight.

In[5]:= RotateLeft[{a, b, c, d, e}, -2]

Out[5]=

Advanced Topic: Lists as SetsGrouping Together Elements of Lists