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:

Introduced in 2014
 (10.0)
 |
Updated in 2019
 (12.0)