KeySortBy

KeySortBy[assoc,f]
sorts the elements of an association in the order defined by applying f to each of their keys.

KeySortBy[f]
represents an operator form of KeySortBy that can be applied to an expression.

DetailsDetails

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Sort the association entries by keys in reverse order:

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

Sort the association by its keys modulo 3:

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

Sort the entries by the length of their keys:

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

Sort a list of rules:

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

Use the operator form of KeySortBy:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 2014
(10.0)