title: Counting the number of duplicates in a list
body: <p>I am trying to construct this function but I can't work out how to stop the function counting the same duplicate more than once. Can someone help me please?</p>
  
  <pre><code>def count_duplicates(seq): 
  
      '''takes as argument a sequence and
      returns the number of duplicate elements'''
  
      fir = 0
      sec = 1
      count = 0
      while fir &lt; len(seq):
          while sec &lt; len(seq):
              if seq[fir] == seq[sec]:
                  count = count + 1
              sec = sec + 1
          fir = fir + 1
          sec = fir + 1
      return count 
  </code></pre>
  
  <p>In: <code>count_duplicates([-1,2,4,2,0,4,4])</code></p>
  
  <p>Out: <code>4</code></p>
  
  <p>It fails here because the output should be <code>3</code>.</p>