Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Flatten keys in a nested association
| ResourceFunction["AssociationKeyFlatten"][assoc] flattens out keys in the nested Association assoc. | |
| ResourceFunction["AssociationKeyFlatten"][assoc,f] maps f over the list of flattened keys. | 
Flatten out keys in an Association:
| In[1]:= | ![assoc = <|
  Subscript[k, 1] -> <|Subscript[k, 11] -> a, Subscript[k, 12] -> b|>,
   Subscript[k, 2] -> <|Subscript[k, 21] -> <|Subscript[k, 211] -> c, Subscript[k, 212] -> d|>|>, Subscript[k, 3] -> <||>, Subscript[k, 4] -> e|>](https://www.wolframcloud.com/obj/resourcesystem/images/69d/69db3426-da6c-4ea6-bfd6-d6700a604003/70b3d4bc7d8535b1.png) | 
| Out[1]= |  | 
| In[2]:= | ![ResourceFunction["AssociationKeyFlatten"][assoc]](https://www.wolframcloud.com/obj/resourcesystem/images/69d/69db3426-da6c-4ea6-bfd6-d6700a604003/1ff70d42250eb019.png) | 
| Out[2]= |  | 
Apply a function to flattened lists of keys:
| In[3]:= | ![ResourceFunction["AssociationKeyFlatten"][assoc, f]](https://www.wolframcloud.com/obj/resourcesystem/images/69d/69db3426-da6c-4ea6-bfd6-d6700a604003/5a6a3d330ea882db.png) | 
| Out[3]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License