Function Repository Resource:

# IntersectionWithDuplicates

Find elements common to multiple lists, including duplicates

Contributed by: Lou D'Andria
 ResourceFunction["IntersectionWithDuplicates"][list1,list2,…] gives a sorted list of the elements common to all the listi, including duplicates.

## Details

An element will appear in the resulting list n times if it appears n times in each of the listi.

## Examples

### Basic Examples (2)

Find elements common to the given lists, with duplicates in the result if there are duplicates in all the lists:

 In[1]:=
 Out[1]=

More than two lists can be given:

 In[2]:=
 Out[2]=

### Applications (1)

Find all prime factors common to two numbers:

 In[3]:=
 Out[3]=

### Properties and Relations (2)

IntersectionWithDuplicates returns all the same elements as Intersection, but possibly with different multiplicities:

 In[4]:=
 Out[4]=
 In[5]:=
 Out[5]=

If there is no intersection, the result is {}:

 In[6]:=
 Out[6]=

Lou D'Andria

## Version History

• 1.0.0 – 08 August 2022