Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Find elements common to multiple lists, including duplicates
ResourceFunction["IntersectionWithDuplicates"][list1,list2,…] gives a sorted list of the elements common to all the listi, including duplicates. |
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]= |
Find all prime factors common to two numbers:
| In[3]:= | ![]() |
| Out[3]= |
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]= |
This work is licensed under a Creative Commons Attribution 4.0 International License