Function Repository Resource:

Duplicates

Source Notebook

Select all the elements that appear twice or more in a list

Contributed by: Sander Huisman

ResourceFunction["Duplicates"][list]

gives back the elements that appear twice or more in list.

Details and Options

Results are given back in the order of first appearance.

Examples

Basic Examples (2) 

Only the repeated elements (1 and 2) are returned:

In[1]:=
ResourceFunction["Duplicates"][{1, 2, 1, 2, 3, 4, 5, 1}]
Out[1]=

Duplicates looks at elements at level 1:

In[2]:=
ResourceFunction[
 "Duplicates"][{{1, 1}, {2, 1}, {1, 1}, {2, 2}, {3, 1}, {4, 4}, {4, 3}, {2, 2}}]
Out[2]=

Properties and Relations (2) 

Duplicates gives all the copies of the repeated elements:

In[3]:=
ResourceFunction["Duplicates"][{1, 2, 1, 2, 3, 4, 5, 1}]
Out[3]=

Use the resource function DuplicatesList to get the unique elements:

In[4]:=
ResourceFunction["DuplicatesList"][
 ResourceFunction["Duplicates"][{1, 2, 1, 2, 3, 4, 5, 1}]]
Out[4]=

Possible Issues (1) 

An empty list is returned if there are no duplicates:

In[5]:=
ResourceFunction["Duplicates"][Range[10]]
Out[5]=

Publisher

SHuisman

Version History

  • 1.0.0 – 11 March 2020

Related Resources

License Information