WolframLang: Association (Key Value Pairs)

By Xah Lee. Date: . Last updated: .

WolframLang's Association is a dedicated structure for list of key/value pairs. Similar to Lisp Association List, JavaScript Map, Python Dictionary, Perl Hash Table. It provides a efficient implementation of ordered list of pairs, when you have large number of pairs such as over a hundred pairs.

Create Association

Association[rule1, rule2 etc]
(short syntax: <|args|> is same as Association[args] )

Association is an ordered list of key/value pairs.

Each rule is a pair of values in one of the form

  • Rule[expr1, expr2] (short syntax expr1 -> expr2)
  • RuleDelayed[expr1, expr2] (short syntax expr1 :> expr2)

The left-hand-side is the key. The right-hand-side is the value. [see WolframLang: Rule]

  • The key or value can be any expression.
  • The key is usually a Symbol or a string.
  • If key are duplicated, the earlier ones are removed.


(* create a key/value pairs list *)
xx = Association[ a -> 3, b -> 2 ]

(* short syntax *)
yy = <| a -> 3, b -> 2 |>

xx === yy
same as Association[args]


Length[ assoc ]
return number of pairs.

WolframLang: Association (Key Value Pairs)