Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Drop keys from a nested association
ResourceFunction["NestedKeyDrop"][assoc,{key}] returns assoc with key dropped. | |
ResourceFunction["NestedKeyDrop"][assoc,{key1,…,keym}] returns assoc with keym dropped deep in the association. | |
ResourceFunction["NestedKeyDrop"][assoc,{{key1,1,…,key1,m},{key2,1,…,key2,n},…}] returns assoc with the key specified by each key sequence dropped deep in the association. | |
ResourceFunction["NestedKeyDrop"][{assoc1,assoc2,…},…] returns a list of associations with keys dropped in each, as specified in the given key sequence(s). |
Drop a key at the top level:
In[1]:= |
Out[1]= |
This is equivalent to KeyDrop:
In[2]:= |
Out[2]= |
Drop a key deep in an association:
In[3]:= |
Out[3]= |
Drop multiple keys from an association:
In[4]:= |
Out[4]= |
Drop multiple keys from a list of associations:
In[5]:= |
Out[5]= |
Keys that do not exist in a given association are ignored:
In[6]:= |
Out[6]= |
NestedKeyDrop supports arbitrary keys:
In[7]:= |
In[8]:= |
Out[8]= |
Where keys are specified as lists, they must be wrapped in Key:
In[9]:= |
Out[9]= |
Where keys are key-literals, they must be given in the form Key[Key[key]]:
In[10]:= |
Out[10]= |
NestedKeyDrop strips off the first Key in each key of the key sequence:
In[11]:= |
Out[11]= |
Not wrapping lists in Key returns a Failure in most cases:
In[12]:= |
Out[12]= |
However, NestedKeyDrop may sometimes interpret a key not wrapped in Key as a list of key sequences of length 1:
In[13]:= |
Out[13]= |
Key-value pairs associated using RuleDelayed anywhere in the given associations are not supported and may cause erroneous behavior:
In[14]:= |
Out[14]= |
This work is licensed under a Creative Commons Attribution 4.0 International License