Skip to main content
3 of 4
deleted 3 characters in body; edited title
Jason B.
  • 70.2k
  • 3
  • 144
  • 298

Find the length of the intersection of two lists including duplicates

I have 2 Lists, yhe first one includes all the numbers from 1 to 10.

listA={1,2,3,4,5,6,7,8,9,10}. 

The second includes random numbers, like

listB={2,10,2,5,7,15,1000,7,25,600}. 

I want to find an algorithm that will take any number of the second list listB and compare it to all numbers in listA. If the numbers equals I"ll get 1 as a result. If not it will be 0. As a final result I would like to sum all equal numbers.

Here, for example we have the result 6 because we can find 2 (twice), 7 (twice), 5 and 10 in the two lists. I need a general way because my lists includes data of 10,000 numbers.

Regards. Danny

Danny
  • 221
  • 1
  • 6