Function Repository Resource:

AssociationKeyFlatten

Source Notebook

Flatten keys in a nested association

Contributed by: Wolfram Research

ResourceFunction["AssociationKeyFlatten"][assoc]

flattens out keys in the nested Association assoc.

ResourceFunction["AssociationKeyFlatten"][assoc,f]

maps f over the list of flattened keys.

Examples

Basic Examples (2) 

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|>
Out[1]=
In[2]:=
ResourceFunction["AssociationKeyFlatten"][assoc]
Out[2]=

Apply a function to flattened lists of keys:

In[3]:=
ResourceFunction["AssociationKeyFlatten"][assoc, f]
Out[3]=

Version History

  • 1.0.0 – 29 May 2019

Related Resources

License Information