title: Fastest way to compare ordered lists and count common elements *including* duplicates
body: <p>I need to compare two lists of numbers and count how many elements of first list are there in second list. For example,</p>
  
  <pre><code>a =  [2, 3, 3, 4, 4, 5]
  b1 = [0, 2, 2, 3, 3, 4, 6, 8]
  </code></pre>
  
  <p>here I should get result of 4: I should count '2' 1 time (as it happens only once in first list), '3' - 2 times, '4' - 1 time (as it happens only once in second list). I was using the following code:</p>
  
  <pre><code>def scoreIn(list1, list2):
     score=0
     list2c=list(list2)
     for i in list1:
        if i in list2c:
           score+=1
           list2c.remove(i)
     return score
  </code></pre>
  
  <p>it works correctly, but too slow for my case (I call it 15000 times). I read a hint about 'walking' through sorted lists which was supposed to be faster, so I tried to do like that:</p>
  
  <pre><code>def scoreWalk(list1, list2):
     score=0
     i=0
     j=0
     len1=len(list1) # we assume that list2 is never shorter than list1
     while i&lt;len1:
        if list1[i]==list2[j]:
           score+=1
           i+=1
           j+=1
        elif list1[i]&gt;list2[j]:
           j+=1
        else:
           i+=1
     return score
  </code></pre>
  
  <p>Unfortunately this code is even slower. Is there any way to make it more efficient? In my case, both lists are sorted, contains only integers, and list1 is never longer than list2.</p>