Wolfram Research

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

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

Duplicates gives all the copies of the repeated elements:

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

Use DuplicatesList to get the unique elements:

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

Possible Issues

An empty list is returned if there are no duplicates:

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

Resource History

Related Resources

License Information