title: list indices must be integers or slices, not NoneType
body: <p>I was dealing with this problem when I am trying to create quick sort on my own
  I don't know how to fix the error and I most certainly do not know if any other problem exists in my code.</p>
  
  <pre><code>def Qsort(list):
      if len(list) &lt; 2:
          return list
      Qsorthelper(list, 0, len(list)-1)
  
  def Qsorthelper(list, first, last):
      if last&gt;first:
          split=partition(list, first, last)
          Qsorthelper(list, first, split-1)
          Qsorthelper(list, split+1, last)
  
  def median(list):
      if len(list) %2 == 0:
          return (len(list)//2+len(list)//2-1)/2
      else:
          return len(list)//2
  
  def finditem(list, num):
      for i in range(0,len(list)-1):
          if num == list[i]:
              return i
  
  
  def choosepivot(list):
      if list[0] &gt; list[len(list)-1] &gt; list[median(list)] or list[0] &lt; 
      list[len(list)-1] &lt; list[median(list)]:
          return list[len(list)-1]
      elif list[len(list)-1] &gt; list[0] &gt; list[median(list)] or 
      list[len(list)-1] &lt; list[0] &lt; list[median(list)]:
          return list[0]
      else:
          return list[median(list)]
  
  
  
  def partition(list, first, last):
      pivot = choosepivot(list)
      list.append(pivot)
      list.remove(pivot)
      left = list[first]
      right = list[last-1]
      done = False
  
      while not done:
          while left &lt;= right and list[left] &lt;= pivot:
              left = left + 1
  
          while right &gt;= left and list[right] &gt;= pivot:
              right = right - 1
  
          if right &lt; left:
              done = True
          else:
              temp = list[left]
              list[left] = list[right]
              list[right] = temp
  
      temp = list[finditem(list,pivot)]
      list[finditem(list,pivot)] = list[right]
      list[right] = temp
  
      return right
  
  alist = [54,26,93,17,77,31,44,55,20]
  Qsort(alist)
  print(alist)
  </code></pre>
  
  <p>I don't know what is the problem that caused the error but I really want to fix it
  any suggestions or answers?</p>
  
  <p>edit:
  I changed the finditem part to fix the i not finding the last element:</p>
  
  <pre><code>def finditem(alist, num):
      for i in range(0,len(alist)):
          if num == alist[i]:
              return i
  </code></pre>
  
  <p>and I got this error:</p>
  
  <pre><code>File "C:\Users\user\Desktop\ITB\failed quick sort.py", line 59, in partition
      alist[finditem(alist,pivot)] = alist[right]
  IndexError: list index out of range
  &gt;&gt;&gt; 
  
  temp = list[finditem(list,pivot)]
  list[finditem(list,pivot)] = list[right]
  list[right] = temp
  </code></pre>
  
  <p>this ipart is the part where I switch the final item with the pivot to complete one cycle, something is wrong here but I want to know how.</p>