title: How can I count duplicates in a nested list based on first two elements in python
body: <p>I have a list in the form:</p>
  
  <pre><code>lst = [[1, 0, 0, 0], [1, 1, 0, 0], [2, 0, 0, 0], [2, 1, 0, 0], [2, 1, 0, 0], [1, 1, 0, 0], [3, 1, 0, 0], [1, 3, 0, 0], [2, 1, 0, 0], [2, 0, 0, 0]]
  </code></pre>
  
  <p>However the last two sub-elements will always be zero at the start so it could be like:</p>
  
  <pre><code>lst = [[1, 0], [1, 1], [2, 0], [2, 1], [2, 1], [1, 1], [3, 1], [1, 3], [2, 1], [2, 0]]
  </code></pre>
  
  <p>If that is easier.</p>
  
  <p>What I want is to remove and count the duplicates of this list and set the 3rd sub-element to the count so if we take the above I want:</p>
  
  <pre><code>lst = [[1, 0, 1, 0], [1, 1, 2, 0], [2, 0, 2, 0], [2, 1, 3, 0], [3, 1, 1, 0], [1, 3, 1, 0]]
  </code></pre>
  
  <p>I have found explanations of how to remove duplicates at:
  <a href="https://stackoverflow.com/questions/12902950/removing-duplicates-from-nested-list-based-on-first-2-elements">Removing Duplicates from Nested List Based on First 2 Elements</a>
  and
  <a href="https://stackoverflow.com/questions/1143379/removing-duplicates-from-list-of-lists-in-python/1143432#1143432">Removing duplicates from list of lists in Python</a></p>
  
  <p>but I don't know how to count the duplicates. The order of the elements in the overall list doesn't matter but the order of the elements in the sub-lists must be preserved as [1,3] and [3,1] aren't the same thing.</p>
  
  <p>If this turns out to be a dead end I could do something like hash the first two elements for counting but only if I could get them back after counting.</p>
  
  <p>Any help is appreciated.
  Sorry for dyslexia!</p>