title: quick sort python recursion
body: <p>This is my quick sort code, the <code>partition</code> function works well, but I got a problem while calling the recursion. The <code>pos</code> changes every time it starts the function and then the list limits are change as well. How to fix that?</p>
  
  <pre><code>def partition(lst, start, end):
  
      pos=0
      if len(lst)&lt;2:
          return 
      for i in range(len(lst[start:end])):
          if lst[i] &lt; lst[end]:
              lst[i],lst[pos]=lst[pos],lst[i]
              pos+=1
  
          elif i==(len(lst[start:end])-1):
              lst[end],lst[pos]=lst[pos],lst[end]
  
      return pos
  
  def quick_sort_recursive(lst, start, end):
  
          pos=partition(lst, start, end)
      if start&lt;=pos&lt;=end :
          quick_sort_recursive(lst, start, pos-1)
          quick_sort_recursive(lst, pos+1, end)
      else:
          return lst
  </code></pre>