Associations

Along with lists, associations are fundamental constructs in the Wolfram Language. They associate keys with values, allowing highly efficient lookup and updating, even with millions of elements. Associations provide generalizations of symbolically indexed lists, associative arrays, dictionaries, hashmaps, structs, and a variety of other powerful data structures.

Association ( <||> ) an association between keys and values

<||>[key] extract the value associated with any given key

Associations and Parts

<||>[["str"]] extract a value corresponding to a key that is a string

Key indicate a key within a part specification

Missing default value if a key is not found

#name a slot in a pure function that picks out value with key "name" in an association

AssociationQ test if an expression is a valid association

Elements of Associations

Keys list of keys

Values list of values

Normal convert to a list of rules

Lookup perform a lookup of a value by key, returning a specified default if it is not found

KeyExistsQ test whether a key exists in an association

Functions That Apply to Values »

Map  ▪  Select  ▪  Sort  ▪  DeleteDuplicates  ▪  ListPlot  ▪  Plus  ▪  ...

Functions That Apply to Keys

KeySort, KeySortBy sort an association by its keys

KeyTake, KeyDrop take, drop particular keys in an association

KeySelect select elements based on a criterion on their keys

KeyMap map a function over the keys in an association

KeyValueMap map a function over keys and values in an association

KeyMemberQ  ▪  KeyFreeQ

Modifying Associations

<||>[key]=val change an element of an association

AssociateTo add elements to an association

KeyDropFrom drop elements from an association

Pattern Matching with Associations

KeyValuePattern elements that can appear anywhere in an association

Functions That Create Associations

Association turn a list of rules into an association

AssociationMap create an association by applying a function to a list of keys

AssociationThread create an association from a list of keys and a list of values

Counts, CountsBy associate values with the number of times they occur

GroupBy group values by collecting those sharing a criterion ("map reduce")

PositionIndex build an index of positions at which values occur

Functions Operating on Lists of Associations

KeyUnion  ▪  KeyIntersection  ▪  KeyComplement

Catenate catenate elements from multiple associations

Merge merge associations using a function to combine elements with common keys

JoinAcross do the analog of a database join on multiple associations

Dataset representation supporting general structured data queries