title: Quicksort python implementation
body: <p>I am trying to write an implementation of quicksort where the pivot element is pseudo-random. I have looked at various posts online, many on SO but I am still having issues. Here is my code:</p>
  
  <pre><code>def quickSort(lst, a, b):
      if a &lt; b:
          pivot = partition(lst, a, b)
          quickSort(lst, a, pivot-1)
          quickSort(lst, pivot+1, b)
      return lst
  
  
  
  def partition(lst, a ,b):
      pivot = random.randint(a,b)
      for i in range(a,b):
          if lst[i] &lt; lst[b]:
              lst[i],lst[pivot] = lst[pivot],lst[i]
              pivot += 1
      lst[pivot],lst[b] = lst[b],lst[pivot]
      return pivot
  </code></pre>
  
  <p>This code is practically identical to the code provided for the answer to this question: <a href="https://stackoverflow.com/questions/20175380/quick-sort-python-recursion">quick sort python recursion</a> but instead of using the <code>start</code> element as the pivot, I am using random. I keep getting this error: </p>
  
  <pre><code> in partition
      lst[pivot],lst[b] = lst[b],lst[pivot]
  IndexError: list index out of range
  </code></pre>
  
  <p>I have looked that up and I think it means that I am trying to reference an element of the list that doesn't exist or is out of the range of the list. Why is this happening?</p>
  
  <p>I have also tried using the style of quicksort implemented in this link and I am getting the same error: <a href="https://stackoverflow.com/questions/26634593/quicksort-implementation-in-python">Quicksort implementation in Python</a></p>