SortAlphabetical
SortAlphabetical
SortAlphabetical[ list ] returns a copy of a list sorted in alphabetical order of the variable names.
Usages
SortAlphabetical[ list ]
SortAlphabetical[ list ] returns a new list with the elements of list sorted alphabetically. An element with one variable is sorted by the name of that variable, so 2x and x^2 are sorted as x. Uppercase letters come before lowercase letters.
| Example | in | out |
|---|---|---|
| Variables. | SortAlphabetical[ {c, a, b} ] |
{a, b, c} |
| Expressions are sorted by their variable. | SortAlphabetical[ {y, 2x, x^2, a} ] |
{a, 2x, x^2, y} |
| Uppercase before lowercase. | SortAlphabetical[ {B, a, A, b} ] |
{A, B, a, b} |
Details
- Equal names keep their original order: in the second example,
2xstays beforex^2.
| Invalid input | Result |
|---|---|
SortAlphabetical[ 5 ] |
Error: the argument should be a list |
Warning
SortAlphabetical is meant for variables and expressions with one variable. Other elements are not sorted in a meaningful way: numbers are sorted as text (SortAlphabetical[ {3, 1, 10, 2} ] gives {1, 10, 2, 3}), and texts and expressions with more variables are not sorted by their content. Use Sort for numbers.
See also: SortAlphabeticalI, Sort