KeySort

KeySort[assoc]

orders the elements of an association by sorting its keys.

KeySort[assoc,p]

orders the elements of an association using the ordering function p.

Details

  • KeySort[assoc] returns an Association object formed in effect by applying Sort to Keys[assoc].
  • In KeySort[assoc,p], the ordering function p is applied to pairs of keys using the same specifications as in Sort.

Examples

open allclose all

Basic Examples  (2)

Sort the elements in an association by their keys:

Sort a list of rules:

Scope  (1)

Construct an association with Spanish words as keys:

Sorting the keys with Spanish alphabetic order is different from sorting with the default English ordering:

Properties & Relations  (1)

Use KeySort to sort an association by keys:

Use Sort to sort the association by values:

Wolfram Research (2014), KeySort, Wolfram Language function, https://reference.wolfram.com/language/ref/KeySort.html (updated 2019).

Text

Wolfram Research (2014), KeySort, Wolfram Language function, https://reference.wolfram.com/language/ref/KeySort.html (updated 2019).

CMS

Wolfram Language. 2014. "KeySort." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2019. https://reference.wolfram.com/language/ref/KeySort.html.

APA

Wolfram Language. (2014). KeySort. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KeySort.html

BibTeX

@misc{reference.wolfram_2023_keysort, author="Wolfram Research", title="{KeySort}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/KeySort.html}", note=[Accessed: 19-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_keysort, organization={Wolfram Research}, title={KeySort}, year={2019}, url={https://reference.wolfram.com/language/ref/KeySort.html}, note=[Accessed: 19-March-2024 ]}