up previous next
sorted

sort a list

Syntax
sorted(L: LIST): LIST

Description
This function returns the list of the sorted elements of L without affecting L, itself.

For more on the default comparisons, see Relational Operators in the chapter on operators. For more complicated sorting, see SortBy , SortedBy .

Example
/**/  L := [3,2,1];
/**/  sorted(L);
[1, 2, 3]

/**/  use R ::= QQ[x,y,z];
/**/  L := [x,y,z];
/**/  sorted(L);
[z, y, x]

/**/  sorted([y, x, z, x^2]);
[z, y, x, x^2]

/**/  sorted([3, 1, 1, 2]);
[1, 1, 2, 3]

/**/  sorted(["b","c","a"]);
["a", "b", "c"]

See Also