KeyMap
Details
Examples
open all close allBasic Examples (2)
Map a function over the keys of an association:
KeyMap[f, <|a -> 1, b -> 2, c -> 3|>]Use the operator form of KeyMap:
KeyMap[f][<|a -> 1, b -> 2, c -> 3|>]Scope (1)
In KeyMap[f,assoc], if applying f produces repeated keys, later instances replace earlier ones:
KeyMap[Abs, <|1 -> a, 2 -> b, -1 -> c|>]Properties & Relations (4)
KeyMap[f,assoc] is equivalent to AssociationThread[Map[f,Keys[assoc]]Values[assoc]]:
assoc = <|1 -> a, 2 -> b, 3 -> c|>;KeyMap[f, assoc] === AssociationThread[Map[f, Keys[assoc]] -> Values[assoc]]KeyMap[f,assoc] gives an association with the same length as DeleteDuplicatesBy[Keys[assoc],f]:
assoc = <|0 -> a, (π/2) -> b, π -> c|>;Length[KeyMap[Sin, assoc]] == Length[DeleteDuplicatesBy[Keys[assoc], Sin]]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|>]KeyValueMap maps a function over the keys and values in an association (and returns a list):
KeyValueMap[f, <|a -> 1, b -> 2, c -> 3|>]AssociationMap maps a function over the rules in an association:
AssociationMap[Reverse, <|a -> 1, b -> 2, c -> 3|>]KeyMap can be parallelized automatically:
Parallelize[KeyMap[Prime, AssociationMap[Identity, Range[10]]]]Related Guides
History
Text
Wolfram Research (2014), KeyMap, Wolfram Language function, https://reference.wolfram.com/language/ref/KeyMap.html.
CMS
Wolfram Language. 2014. "KeyMap." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/KeyMap.html.
APA
Wolfram Language. (2014). KeyMap. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KeyMap.html
BibTeX
@misc{reference.wolfram_2026_keymap, author="Wolfram Research", title="{KeyMap}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/KeyMap.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_keymap, organization={Wolfram Research}, title={KeyMap}, year={2014}, url={https://reference.wolfram.com/language/ref/KeyMap.html}, note=[Accessed: 12-June-2026]}