Function Repository Resource:

Untally

Source Notebook

Make a list from tallied results

Contributed by: Sander Huisman

ResourceFunction["Untally"][{{e1,c1},{e2,c2},}]

makes one long list with each ei appearing ci times, reversing the results of Tally.

Examples

Basic Examples (2) 

Make a list of items given by their multiplicity:

In[1]:=
ResourceFunction["Untally"][{{s, 6}, {g, 6}, {h, 7}}]
Out[1]=

Reverse a tally:

In[2]:=
tally = Tally[{a, a, a, b, b, c, c, c, c}];
ResourceFunction["Untally"][tally]
Out[3]=

Applications (3) 

Randomize the results:

In[4]:=
tally = Tally[{a, a, a, b, b, c, c, c, c}];
RandomSample[ResourceFunction["Untally"][tally]]
Out[5]=

An untally with a RandomChoice, which uses the weights of the tally for randomly creating the elements:

In[6]:=
tally = Tally[{a, a, a, a, b, c, c}];
RandomChoice[ResourceFunction["Untally"][tally]]
Out[7]=

Using DeleteDuplicates is the same as applying DeleteDuplicates to the original data:

In[8]:=
tally = Tally[{a, a, a, b, b, c, c, c, c}];
DeleteDuplicates[ResourceFunction["Untally"][tally]]
Out[9]=

Possible Issues (1) 

The original order can not be reconstructed again:

In[10]:=
tally = Tally[{b, a, c, a, b, c, a, b}];
ResourceFunction["Untally"][tally]
Out[11]=

Publisher

SHuisman

Version History

  • 1.0.0 – 15 February 2023

Related Resources

License Information