Function Repository Resource:

DuplicatesList

Source Notebook

Give the elements that appear more than once in the input list

Contributed by: Wolfram Staff

ResourceFunction["DuplicatesList"][list]

gives those elements in list that appear more than once.

ResourceFunction["DuplicatesList"][list,test]

applies test to pairs of elements to determine if they should be considered identical.

Details and Options

The default function used to test whether elements are identical is SameQ.

Examples

Basic Examples (1) 

Find the duplicates in a List:

In[1]:=
ResourceFunction["DuplicatesList"][{x, y, x, z, y, w}]
Out[1]=

Properties and Relations (1) 

DuplicatesList[list] is equivalent to Map[First,DeleteCases[Gather[list],{_}]]

In[2]:=
list = RandomInteger[20, 100]
Out[2]=
In[3]:=
ResourceFunction["DuplicatesList"][list]
Out[3]=
In[4]:=
Map[First, DeleteCases[Gather[list], {_}]]
Out[4]=

Version History

  • 1.0.0 – 21 June 2019

Author Notes

This is based on a suggested implementation from Jose Martin-Garcia

License Information