0

Is there a way I can calculate the Intersection of two lists that have duplicates in them. For example.

list1=[1,2,3,4,4,4,5]
list2=[4,4,5,5,6]

result would be:

[4,4,5]

I tried the intersection() function in pandas but that uses sets not lists

Kraigolas
  • 5,121
  • 3
  • 12
  • 37
  • Also this: [Intersection of two lists including duplicates?](https://stackoverflow.com/questions/37645053/intersection-of-two-lists-including-duplicates) – Nathaniel Ford Nov 10 '22 at 22:18
  • @TomKarzes: The one it was duped to was bad, but [Nathaniel Ford's duplicate, "Intersection of two lists including duplicates?"](https://stackoverflow.com/q/37645053/364696) is a perfect dupe (which I've added as the top duplicate). – ShadowRanger Nov 10 '22 at 22:25
  • @ShadowRanger Yes, exactly as I said in my comment. `collections.Counter` is clearly the simplest solution. – Tom Karzes Nov 10 '22 at 22:27

0 Answers0