Wolfram Research

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

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]=

Resource History

See Also

License Information