Function Repository Resource:

# AssociationKeyDeflatten

Deflatten the keys in a flat Association to create a nested Association

Contributed by: Richard Hennigan (Wolfram Research)
 ResourceFunction["AssociationKeyDeflatten"][<|{k1,1,k1,2,…}→val1,{k2,1,k2,2,…}→val2,…|>] gives a nested Association assoc where each valn is found at assoc[kn,1,kn,2,…]. ResourceFunction["AssociationKeyDeflatten"][assoc,f] uses f to interpret the keys of assoc as lists.

## Details and Options

ResourceFunction["AssociationKeyDeflatten"] is an inverse for the resource function AssociationKeyFlatten.

## Examples

### Basic Examples (4)

Create a nested Association from a flat Association with lists as keys:

 In[1]:=
 Out[1]=

Keys not wrapped in a list are unchanged:

 In[2]:=
 Out[2]=

Provide a function to interpret keys as lists:

 In[3]:=
 Out[3]=

Values held by RuleDelayed will not be evaluated:

 In[4]:=
 Out[4]=

### Scope (1)

AssociationKeyDeflatten also works with lists of rules:

 In[5]:=
 Out[5]=
 In[6]:=
 Out[6]=

### Properties and Relations (2)

Deflatten the keys of an Association:

 In[7]:=
 Out[7]=
 In[8]:=
 Out[8]=

Use AssociationKeyFlatten to get the original Association:

 In[9]:=
 Out[9]=

If f and g are partial inverses of each other, AssociationKeyDeflatten[,f] and AssociationKeyFlatten[,g] typically will be as well:

 In[10]:=
 In[11]:=
 Out[11]=
 In[12]:=
 Out[12]=
 In[13]:=
 Out[13]=
 In[14]:=
 Out[14]=

### Neat Examples (3)

Convert an Association where keys are file paths into a nested Association:

 In[15]:=
 Out[15]=
 In[16]:=
 Out[16]=

Get everything under a particular directory:

 In[17]:=
 Out[17]=

Revert to the flat Association:

 In[18]:=
 Out[18]=
 In[19]:=
 Out[19]=

## Version History

• 1.0.0 – 30 September 2020