This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
 Documentation / Mathematica / Built-in Functions / Lists and Matrices / List Operations  /
Sort

  • Sort[ list ] sorts the elements of list into canonical order.
  • Sort[ list , p ] sorts using the ordering function p.
  • Example: Sort[ b, c, a ].
  • The canonical ordering used by Mathematica is described in Section¬†A.3.9.
  • Sort[ list , p ] applies the function p to pairs of elements in list to determine whether they are in order. The default function p is OrderedQ[{#1, #2}]&.
  • Example: Sort[ 4, 1, 3 , Greater].
  • Sort can be used on expressions with any head, not only List.
  • See the Mathematica book: Section 1.8.9,¬†Section 2.2.10.
  • See also: Order, OrderedQ, Orderless.

    Further Examples

    You can put a list of letters into canonical order.

    In[1]:=

    Out[1]=

    Both of these commands sort the list from largest to smallest.

    In[2]:=

    Out[2]=

    In[3]:=

    Out[3]=

    This puts elements that do not depend on x before those that do.

    In[4]:=

    Out[4]=