title: Python quickselect sorting
body: <p>The program is supposed to use quick select and return the median of a set of integer values. </p>
  
  <p>Question: When I run the program, it tells me that k is not defined. How should I define k to get the median?</p>
  
  <pre><code>def quickSelect(lines,k):
      if len(lines)!=0:
          pivot=lines[(len(lines)//2)]
          smallerlist=[]
          for i in lines:
              if i&lt;pivot:
                  smallerlist.append(i)
          largerlist=[]
          for i in lines:
              if i&gt;pivot:
                  largerlist.append(i)
          m=len(smallerlist)
          count=len(lines)-len(smallerlist)-len(largerlist)
          if k &gt;= m and k&lt;m + count:
              return pivot
          elif m &gt; k:
              return quickSelect(smallerList,k)
          else:
              return quickSelect(largerList, k - m - count)
  </code></pre>