LexicographicSort[{e1,e2,…}]
sorts the list of expressions ei in lexicographic order.
LexicographicSort[{e1,e2,…},p]
compares elements of the ei expressions using the ordering function p.


LexicographicSort
LexicographicSort[{e1,e2,…}]
sorts the list of expressions ei in lexicographic order.
LexicographicSort[{e1,e2,…},p]
compares elements of the ei expressions using the ordering function p.
Details

- Lexicographic sorting is also known as lexical sorting and dictionary sorting.
- By default, LexicographicSort compares elements of the ei expressions using canonical Order.
- LexicographicSort[{string1,string2,…}] sorts by lexicographic order of the lists of characters of the strings.
- LexicographicSort[list,p] is equivalent to Sort[list,LexicographicOrder[p]].
Examples
open all close allBasic Examples (1)
Scope (5)
Sort lexicographically the elements of a list:
Use an ordering function to compare respective subexpressions of the elements:
Sort lexicographically expressions with heads other than List:
Sort lexicographically a list of strings:
Sort lexicographically a list of associations, comparing respective values:
Properties & Relations (6)
Order is determined by the first element that differs, regardless of expression length:
When all elements coincide up to the shortest length, shorter lists are ordered first:
Empty lists are sorted before any other list:
LexicographicSort[list] is equivalent to Sort[list,LexicographicOrder]:
For lists of the same length, LexicographicSort is equivalent to Sort:
LexicographicSort with strings of letters is equivalent to AlphabeticSort with default options:
AlphabeticSort and Sort are not lexicographic when the strings contain letters and numbers:
Related Guides
History
Text
Wolfram Research (2021), LexicographicSort, Wolfram Language function, https://reference.wolfram.com/language/ref/LexicographicSort.html.
CMS
Wolfram Language. 2021. "LexicographicSort." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/LexicographicSort.html.
APA
Wolfram Language. (2021). LexicographicSort. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/LexicographicSort.html
BibTeX
@misc{reference.wolfram_2025_lexicographicsort, author="Wolfram Research", title="{LexicographicSort}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/LexicographicSort.html}", note=[Accessed: 14-August-2025]}
BibLaTeX
@online{reference.wolfram_2025_lexicographicsort, organization={Wolfram Research}, title={LexicographicSort}, year={2021}, url={https://reference.wolfram.com/language/ref/LexicographicSort.html}, note=[Accessed: 14-August-2025]}