Association[key1val1,key2val2,…] or key1val1,key2val2,…
represents an association between keys and values.
Association 
Association[key1val1,key2val2,…] or key1val1,key2val2,…
represents an association between keys and values.
Details
- The value associated with a given key k in the association assoc can be extracted using assoc[k]. »
- An association acts like a symbolically indexed list. The value associated with a given key k can be extracted using the part specification Key[k]. If k is a string, Key can be omitted. »
- If key is not present in assoc, assoc[key] yields Missing["KeyAbsent",key]. »
- If assoc is a symbol whose value is an association, assoc[key]=val can be used to associate or reset the association of key with val. »
- Typical list operations (such as Map, Select and Sort) apply to the values in an association, leaving the keys unchanged. »
- Association[{key1val1,…}] gives <|key1val1,…|>. »
- If there are multiple elements with the same key, all but the last of these elements are dropped. Merge yields instead a list of values for repeated keys.
- Associations can be input using the characters \[LeftAssociation] and \[RightAssociation]. These can be entered with
<|
and
|>
, respectively. - Normal converts an Association object to a list of rules. »
- KeyValuePattern can be used to represent a pattern for associations that include particular elements. »
Examples
open all close allBasic Examples (4)
An association in which key a is associated with value x, key b with value y, etc.:
Extract the value associated with key b:
Convert a list of rules to an association:
Associations can be modified by resetting values:
The key b now has value w rather than y:
Using delayed rules prevents the values from being evaluated during association construction:
Scope (17)
Construction and Extraction (9)
Associations can have arbitrary expressions as keys, including associations:
Associations work with any number of elements:
Extracting values from an association is highly efficient:
Missing elements are represented by Missing:
Lookup allows a default value to be given:
Extract a value from an association using Part:
Extract a portion of the value:
The Key[k] part specification works at any level whose value is an association:
Extract the third value in an association:
Extract the value associated with the key 3:
Obtain the sub-association consisting of the second and third parts of an association:
Extract the value associated with the key {2,3}:
Extract a value using Extract:
Obtain the value without letting it evaluate:
Separate an association into a list of keys and a list of values:
Pattern-Matching Operations (8)
Associations can be used for pattern matching:
Extract key and value from an association:
Replace arguments of a function:
Pick the rule with the specific key:
Filter associations with length 2 only:
Define a function using an association as an argument:
Use nested associations as a function argument:
KeyValuePattern lets you match any element in an association:
KeyValuePattern matches elements that appear anywhere in an association:
Properties & Relations (9)
Keys are "transparent" for typical list operations:
Values extracts values from an association:
Keys extracts keys from an association:
Normal turns an association into a list of rules:
Position gives keys in an association:
Values in associations can be extracted like parts:
If the key in an association is a string, no explicit Key is needed to extract it as a part:
Numerical part specifications work structurally on associations:
Associations keep only the last instance of repeated keys:
When an association is modified, a new copy is created:
Possible Issues (2)
Association counts as one level, not two, in structural functions:
Lists of rules are two levels:
See Also
List Tabular Dataset Normal AssociationQ Lookup KeyExistsQ Keys Values KeyValuePattern SparseArray CompoundElement DataStructure Tree
Function Repository: AssociatePairs ToAssociations SparseAssociation AssociationEditor
Related Guides
-
▪
- Associations ▪
- Computation with Structured Datasets ▪
- Automated Reports ▪
- WDF (Wolfram Data Framework) ▪
- Language Overview ▪
- Setting Up Input Interpreters ▪
- Wolfram Language Syntax Characters ▪
- Expressions ▪
- Wolfram Language Syntax ▪
- Database Connectivity ▪
- Scientific Data Analysis ▪
- Wolfram Data Repository
Related Workflows
Text
Wolfram Research (2014), Association, Wolfram Language function, https://reference.wolfram.com/language/ref/Association.html (updated 2016).
CMS
Wolfram Language. 2014. "Association." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2016. https://reference.wolfram.com/language/ref/Association.html.
APA
Wolfram Language. (2014). Association. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Association.html
BibTeX
@misc{reference.wolfram_2025_association, author="Wolfram Research", title="{Association}", year="2016", howpublished="\url{https://reference.wolfram.com/language/ref/Association.html}", note=[Accessed: 15-November-2025]}
BibLaTeX
@online{reference.wolfram_2025_association, organization={Wolfram Research}, title={Association}, year={2016}, url={https://reference.wolfram.com/language/ref/Association.html}, note=[Accessed: 15-November-2025]}