Wolfram: Association (Key Value List)
What is Association
WolframLang's Association is a dedicated structure for list of key value pairs. It provides a efficient implementation of ordered list of pairs, when you have large number of pairs such as over a thousand pairs.
💡 TIP: Similar to • JS: Map (aka Dictionary) • Python: Dictionary • Perl: Hash Table • Java: Map • Elisp: Association List
Association Syntax
Association[rule1, rule2, etc]
-
🔸 SHORT SYNTAX:
<|args|>
Association is an ordered list of (key and value) pairs.
Each rule is one of:
Rule[key, val]
RuleDelayed[key, val]
〔see Wolfram: Rule, RuleDelayed〕
- The key can be any Expression.
- The value can be any Expression.
- If a key already exist, the earlier one is removed.
(* create a association. string keys *) xx = Association[ "a" -> 3, "b" -> 2 ] (* <|a -> 3, b -> 2|> *) (* short syntax *) yy = <| "a" -> 3, "b" -> 2 |> (* <|a -> 3, b -> 2|> *) xx === yy (* True *)
Symbol keys
(* create a association, symbol keys *) xx = Association[ a -> 3, b -> 2 ] (* <|a -> 3, b -> 2|> *)
Integer keys
(* create a association, integer keys *) xx = Association[ 5 -> 3, 4 -> 2 ] (* <|5 -> 3, 4 -> 2|> *)
Arbitrary Expression as Keys
(* create a association, arbitrary expression as keys *) xx = Association[ f[x] -> 3, Sin[b] -> 2 ] (* <|f[x] -> 3, Sin[b] -> 2|> *)
Association[{args}]
-
same as
Association[args]
Length
Length[ asso ]
-
number of items.
Check If is Association
AssociationQ[expr]
-
return true if expr is an association.
xx = Association[ "a" -> 3, "b" -> 2 ]; AssociationQ[xx] (* True *)
WolframLang, Association (Key Value List)
- Wolfram: Association (Key Value List)
- Wolfram: Create Association
- Wolfram: Association. Get Value
- Wolfram: Association. Check Key Exist
- Wolfram: Association. Check Value Exist
- Wolfram: Association. Add Item
- Wolfram: Association. Delete Items by Key
- Wolfram: Association. Delete Items by Index
- Wolfram: Association. Delete Items by Filter
- Wolfram: Association. Sort
- Wolfram: Association. Union, Intersection, Complement, Etc
- Wolfram: Map f to Association
- Wolfram: Association to List, Get All Keys or Values