AssociationMap[f,{key1,key2,…}]
creates the association key1f[key1],key2f[key2],….
AssociationMap[f,key1val1,key2val2,…]
creates the association f[key1val1],f[key2val2],….
represents an operator form of AssociationMap that can be applied to an expression.
AssociationMap
AssociationMap[f,{key1,key2,…}]
creates the association key1f[key1],key2f[key2],….
AssociationMap[f,key1val1,key2val2,…]
creates the association f[key1val1],f[key2val2],….
represents an operator form of AssociationMap that can be applied to an expression.
Details
- AssociationMap is typically used to apply a single common function to each of a list of arguments, creating an association of the corresponding values.
- If AssociationMap[f,…] produces repeated keys, later instances replace earlier ones. »
- If AssociationMap produces repeated keys, later instances replace earlier ones. »
- AssociationMap uses the keys as arguments to produce the values. AssociationComap uses the keys as heads. »
- AssociationMap[f][expr] is equivalent to AssociationMap[f,expr].
- Parallelize[AssociationMap[f,{key1,key2,…}]] computes AssociationMap[f,{key1,key2,…}] in parallel on all subkernels. »
Examples
open all close allBasic Examples (3)
Create an association by mapping a function over a list of keys:
AssociationMap[f, {a, b, c, d}]Create an "inverted index" by swapping keys and values:
AssociationMap[Reverse, <|a -> 1, b -> 2, c -> 3, d -> 4|>]Use the operator form of AssociationMap:
AssociationMap[f][{a, b, c, d}]Scope (1)
As is standard for associations, if keys are repeated, later instances replace earlier ones:
i = 0;
AssociationMap[{#, i++}&, {a, b, b}]When starting with an association, the application of the function can also produce repeated keys:
AssociationMap[Reverse, <|a -> 1, b -> 2, c -> 1|>]Properties & Relations (6)
AssociationMap[f,{x1,x2,…}] creates an association with keys xi:
AssociationMap[f, {x, y, z}]Keys[%]The values in the association are given by Map[f,{x1,x2,…}]:
Values[%%]% === Map[f, {x, y, z}]AssociationMap[f,{x1,x2,…}] is equivalent to AssociationThread[{x1,x2,…}Map[f,{x1,x2,…}]]:
AssociationMap[f, {x, y, z}]Map[f, {x, y, z}]%% === AssociationThread[{x, y, z} -> %]AssociationMap[f,list] gives an association with the same length as DeleteDuplicates[list]:
list = {a, b, b};AssociationMap[f, list]Length[%] == Length[DeleteDuplicates[list]]AssociationMap maps a function over the rules in an association:
AssociationMap[Reverse, <|a -> 1, b -> 2, c -> 3|>]KeyValueMap maps a function over the keys and values in an association (and returns a list):
KeyValueMap[f, <|a -> 1, b -> 2, c -> 3|>]KeyMap maps a function over the keys in an association:
KeyMap[f, <|a -> 1, b -> 2, c -> 3|>]Map maps a function over the values in an association:
Map[f, <|a -> 1, b -> 2, c -> 3|>]AssociationMap wraps an expression around the keys in a list:
AssociationMap[f, {x, y, z}]AssociationComap wraps the keys in a list around an expression:
AssociationComap[{f, g, h}, x]AssociationMap can be parallelized automatically:
Parallelize[AssociationMap[Prime, Range[10]]]Possible Issues (1)
AssociationMap[f,assoc] can return invalid associations if f does not return a rule:
AssociationMap[Length, <|a -> 1, b -> 2|>]See Also
Map Association KeyValueMap KeyMap AssociationComap Keys Values AssociationThread
Function Repository: ValueMap
Related Guides
History
Text
Wolfram Research (2014), AssociationMap, Wolfram Language function, https://reference.wolfram.com/language/ref/AssociationMap.html.
CMS
Wolfram Language. 2014. "AssociationMap." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/AssociationMap.html.
APA
Wolfram Language. (2014). AssociationMap. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AssociationMap.html
BibTeX
@misc{reference.wolfram_2026_associationmap, author="Wolfram Research", title="{AssociationMap}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/AssociationMap.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_associationmap, organization={Wolfram Research}, title={AssociationMap}, year={2014}, url={https://reference.wolfram.com/language/ref/AssociationMap.html}, note=[Accessed: 13-June-2026]}