WLJS LogoWLJS Notebook

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.

Examples

Sort by keys:

KeySort[<|"c" -> 3, "a" -> 1, "b" -> 2|>]
(* <|"a" -> 1, "b" -> 2, "c" -> 3|> *)

Reverse sort:

KeySort[<|1 -> "a", 3 -> "c", 2 -> "b"|>, Greater]
(* <|3 -> "c", 2 -> "b", 1 -> "a"|> *)

Please visit the official Wolfram Language Reference for more details.

On this page