Function Repository Resource:

KeyReset

Source Notebook

Reset the keys of an Association as values

Contributed by: Ting Sun

ResourceFunction["KeyReset"][asc]

resets keys of an Association to be leading values of each record under asc with a predefined index where appropriate.

ResourceFunction["KeyReset"][asc,name]

specifies the index with a custom name.

ResourceFunction["KeyReset"][name]

represents an operator form of ResourceFunction["KeyReset"] that can be applied to an expression.

Details

ResourceFunction["KeyReset"] works as the inverse function of the resource function KeyIndex.
ResourceFunction["KeyReset"] names the generated indices by invoking Unique["Index"] and turning the result into a String.

Examples

Basic Examples (3) 

Reset keys of an Association:

In[1]:=
ResourceFunction["KeyReset"][<|1 -> <|b -> 2|>, 3 -> <|b -> 4|>|>]
Out[1]=

Reset keys of an Association as values and index them with custom names:

In[2]:=
ResourceFunction["KeyReset"][<|1 -> <|b -> 2|>, 3 -> <|b -> 4|>|>, a]
Out[2]=

Use the operator form:

In[3]:=
ResourceFunction["KeyReset"][a][<|1 -> <|b -> 2|>, 3 -> <|b -> 4|>|>]
Out[3]=

Properties and Relations (1) 

KeyReset works as the inverse function of the resource function KeyIndex:

In[4]:=
data = RandomSample[ResourceData["Meteorite Landings"], 5]
Out[4]=
In[5]:=
dataIndexed = ResourceFunction["KeyIndex"][data, "ID"];
ResourceFunction["KeyReset"]["ID"]@dataIndexed
Out[6]=

Publisher

Ting Sun

Version History

  • 1.0.0 – 27 September 2021

Related Resources

License Information