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

Examples

open allclose all

Basic Examples  (1)

Sort lists using lexicographic order:

Shorter lists are ordered first in canonical order:

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:

Applications  (1)

Sort subsets lexicographically:

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]:

Compare with canonical order:

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:

Wolfram Research (2021), LexicographicSort, Wolfram Language function, https://reference.wolfram.com/language/ref/LexicographicSort.html.

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_2023_lexicographicsort, author="Wolfram Research", title="{LexicographicSort}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/LexicographicSort.html}", note=[Accessed: 19-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_lexicographicsort, organization={Wolfram Research}, title={LexicographicSort}, year={2021}, url={https://reference.wolfram.com/language/ref/LexicographicSort.html}, note=[Accessed: 19-April-2024 ]}