Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Recursively replace lists of rules with associations
| ResourceFunction["ToAssociations"][{key1→val1,key2→val2,…}] recursively replaces lists of rules with associations having the same keys and values. | 
Convert a list of rules to an Association:
| In[1]:= | ![ResourceFunction["ToAssociations"][{a -> 1, b -> 2}]](https://www.wolframcloud.com/obj/resourcesystem/images/03f/03f9ac8a-b9ca-4ed3-8f4e-6476f054192d/693295034ee400b2.png) | 
| Out[1]= |  | 
Convert a nested list of rules:
| In[2]:= | ![ResourceFunction["ToAssociations"][{a -> 1, b -> {c -> 2}}]](https://www.wolframcloud.com/obj/resourcesystem/images/03f/03f9ac8a-b9ca-4ed3-8f4e-6476f054192d/3c7d24458d40871e.png) | 
| Out[2]= |  | 
Convert a mix of associations and rule lists:
| In[3]:= | ![ResourceFunction["ToAssociations"][<|a -> 1, b -> {c -> 2}|>]](https://www.wolframcloud.com/obj/resourcesystem/images/03f/03f9ac8a-b9ca-4ed3-8f4e-6476f054192d/0b2404aa0e31c7c9.png) | 
| Out[3]= |  | 
Convert a mix of lists and associations:
| In[4]:= | ![ResourceFunction[
 "ToAssociations"][{a -> 1, b -> {c -> 2}, d -> <|e -> {f -> 3}|>}]](https://www.wolframcloud.com/obj/resourcesystem/images/03f/03f9ac8a-b9ca-4ed3-8f4e-6476f054192d/59c3155862c2f60d.png) | 
| Out[4]= |  | 
List items that are not in the form {key→value,…} are left alone:
| In[5]:= | ![ResourceFunction["ToAssociations"][{a, {b -> 2}}]](https://www.wolframcloud.com/obj/resourcesystem/images/03f/03f9ac8a-b9ca-4ed3-8f4e-6476f054192d/071e6a1e4df07fbd.png) | 
| Out[5]= |  | 
ToAssociations stops at unevaluated expressions:
| In[6]:= | ![ResourceFunction["ToAssociations"][{a -> 1, b :> {c -> {d -> 2}}}]](https://www.wolframcloud.com/obj/resourcesystem/images/03f/03f9ac8a-b9ca-4ed3-8f4e-6476f054192d/3f135b74dc31b070.png) | 
| Out[6]= |  | 
Evaluate the held part to let ToAssociations continue:
| In[7]:= | ![%[b]](https://www.wolframcloud.com/obj/resourcesystem/images/03f/03f9ac8a-b9ca-4ed3-8f4e-6476f054192d/35f22618b2754829.png) | 
| Out[7]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License