Wolfram: Create Association

By Xah Lee. Date: . Last updated: .

Create by Map Function to a Key List

AssociationMap[f, list]
  • Creats a association.
  • Each item is elem -> f[elem]
AssociationMap[ff, {3,4,5}]
(* <|3 -> ff[3], 4 -> ff[4], 5 -> ff[5]|> *)

Create by Key List and Value List

AssociationThread[ listA -> listB ]

return an asso such that keys are elements in listA, values are corresponding elements in listB.

:> can be used instead of -> to create a delayed rule. 〔see Wolfram: Rule, RuleDelayed

AssociationThread[ {"a", "b", "c"} -> {3,4,5} ]
(* <|a -> 3, b -> 4, c -> 5|> *)
AssociationThread[ {"a", "b", "c"} :> {3,4,5} ]
(* <|a :> 3, b :> 4, c :> 5|> *)

Wolfram. Association (Key Value List)