Legacy Documentation

Mathematica® Teacher's Edition (2002)

This is documentation for an obsolete product.
Current products and services
 Documentation /  Mathematica Teacher's Edition /  The Teacher's Book /  Interlude 1: Lists /

12.8 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 reverses the list.

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

Out[2]=

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

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

Out[3]=

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

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

Out[4]=

You can leave out the last argument to rotate by one position.

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

Out[5]=

The factorial function n! gives the number of ways of ordering objects. The function Permutations allows you to generate these orderings as lists.

This gives the possible permutations of three elements.

In[6]:= TableForm[ Permutations[{a, b, c}] ]

Out[6]//TableForm=