title: Why My Comparison Counter For QuickSort Does NOT Work?
body: <p>My QuickSort implementation, choosing always the first element as a pivot point works. However, when I tried to add counter for comparisons it fails to count properly. My question is how to count the comparisons when using first element as a pivot point? And could someone help me to fix my code. </p>
  
  <pre><code>counter = 0
  def Partition(L):
      global counter
      pivot = L[0]
      i = 0
      swap = 0
      for j in range(1,len(L)):
          if L[j] &lt;= pivot:
              swap = L[i]
              L[i] = L[j]
              L[j] = swap
              i += 1
              counter += 1
  
      swap = L[0]
      L[0] = L[i-1]
      L[i-1] = swap
      return QuickSort(L[:i]) + QuickSort(L[i:])
  
  
  def QuickSort(L):
      if len(L) &lt;= 1:
          return L
      return Partition(L)
  
  print QuickSort([3,9,8,4,6,10,2,5,7,1])
  print 'Correct ANS: 25'
  print 'My ANS:     ',counter
  </code></pre>
  
  <p>The test case I am using at the end is correct one. </p>