next | previous | forward | backward | up | top | index | toc | home

sort(List) -- sort a list

Synopsis

Description

The sort function uses <= to compare elements of the list, which in turn calls upon ?.
i1 : sort {c,e,a,f,b,f}

o1 = {a, b, c, e, f, f}

o1 : List
i2 : sort {4,2,6,3,8,2}

o2 = {2, 2, 3, 4, 6, 8}

o2 : List
Note: we have modified the sort order for strings so that symbols come before alphanumeric characters, and upper and lower case characters are sorted together.

If the elements of the list are polynomials, then the monomial order is used to sort the elements according to their lead terms.

i3 : R = ZZ[a..d,MonomialOrder=>Lex];
i4 : sort{a*d, b^100, c^3*d}

       3    100
o4 = {c d, b   , a*d}

o4 : List

The optional arguments are not used in this version of sort.

Caveat

If a list contains elements of different types, the sorting still occurs, but might not be particularly intuitive.

See also