title: How do I return the index of the target element in a Python array?
body: <p>Currently, when I search for the element that is at the midpoint it returns the correct index, but for any other element it does not work for me.</p>
  <p>I think I am making a mistake when I split the array:</p>
  <pre class="lang-py prettyprint-override"><code>    aList = [1,3,5,6,8,9,10,12,34,56,78,456]
      def recursiveBinarySearch(aList, target):
          #aList = sorted(aList)
          
          if len(aList) == 0:
              return False
          else:
              midpoint = len(aList) // 2
              if aList[midpoint] == target:
                  return aList.index(target)
              else:
                  if target &lt; aList[midpoint]:
                      return recursiveBinarySearch(aList[:midpoint],target)
                  else:
                      return recursiveBinarySearch(aList[midpoint+1:],target)
      
      print(recursiveBinarySearch(aList,9))
  </code></pre>