Wolfram Research

Function Repository Resource:

MultisetSupport

Source Notebook

Determine the support for a multiset

Contributed by: Robert B. Nachbar (Wolfram Solutions)

ResourceFunction["MultisetSupport"][list]

gives the support of the multiset list, effectively sorting the unique elements of list.

ResourceFunction["MultisetSupport"][assoc]

gives the support of the Association multiset assoc, effectively sorting the keys with non-zero values.

Details and Options

The list need not have the head List.
The values of assoc must be counts, that is, non-negative integer values.

Examples

Basic Examples

Give a sorted list of unique elements of the list:

In[1]:=
ResourceFunction["MultisetSupport"][{a, b, a, c}]
Out[1]=

Give a sorted list of the keys with non-zero values:

In[2]:=
ResourceFunction[
 "MultisetSupport"][<|"a" -> 2, "c" -> 2, "b" -> 2, "d" -> 0, "e" -> 1|>]
Out[2]=

Scope

MultisetSupport works with any head, not just List:

In[3]:=
ResourceFunction["MultisetSupport"][f[b, b, a]]
Out[3]=

Properties and Relations

Compare to Union:

In[4]:=
ResourceFunction["MultisetSupport"][{a, b, a, c}]
Out[4]=
In[5]:=
ResourceFunction["MultisetSupport"][<|a -> 2, b -> 1, c -> 1|>]
Out[5]=
In[6]:=
Union[{a, b, a, c}]
Out[6]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

See Also

License Information