John Fredsted asks
whether there is a built-in method in Maple for lexically sorting a list
of lists of small positive integers.
There is not, however, Robert Israel provided two methods for accomplishing the task.
The first uses the standard technique for extending Maple's
that is, assigning a boolean-valued binary function and passing it to
The second method that Robert provided is ingenious. Here it is, in full,
Ls:= sort(Ls, lexorder):
It converts each list into a string, sorts the strings, then converts the strings back to lists.
This method is significantly faster than the previous.
It does, however, have a limitation; it can only operate on lists with positive
integers in the range 1..255.
While that limitation was suitable for the original poster's application,
that will not always be the case.