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 all close all

Basic Examples  (2)

Sort the elements in an association by their keys:

In[1]:=
Click for copyable input
Out[1]=

Sort a list of rules:

In[1]:=
Click for copyable input
Out[1]=

Scope  (1)

Properties & Relations  (1)

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