Sort

Sort[list] sorts the elements in list according to Order.

Attributes[Sort] := {Protected}

Simple examples

Sort a list of numbers:

In[1]:= Sort[{6, 2, 3.2, -5.1}]
Out[1]= {-5.1, 2, 3.2, 6}

Sort a list of strings:

In[2]:= Sort[{"hello", "a", "aa", "zzz"}]
Out[2]= {"a", "aa", "hello", "zzz"}

Sort a list of symbols:

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

Sort a list of heterogenous expressions:

In[4]:= Sort[{5, h, foo[y, 2], bar[a^x]}]
Out[4]= {5, h, bar[a^x], foo[y, 2]}

Further examples

The object to sort need not be a list:

In[1]:= Sort[foo[d, a, b, c]]
Out[1]= foo[a, b, c, d]