old_contents: #!/usr/bin/env python
  # coding=utf-8
  
  def binarysearch(items, v):
      low = 0
      high = len(items)-1
      while low <= high:
          mid = int((low+high)/2)
          if(items[mid] == v):
              return mid
          elif(items[mid] < v):
              low = mid
          else:
              high = mid + 1
      return None
  
  items = [1,2,3,4,5]
  print binarysearch(items, 3)
  print binarysearch(items, 6)
  
new_contents: #!/usr/bin/env python
  # coding=utf-8
  # Standalone python code, version 2.7
  # I can provide older version to compare them with each other
  import os
  import re
  import math
  import time
  
  def binary_search(array, searchingelement):
  	z = array.__len__()
  	last = z
  	mid = int(z/2)
  	min = 0
  	for i in range(int(math.log(z)/math.log(2)) + 1):
  		if array[mid] == searchingelement:
  			return str(mid) + " th index"
  		elif array[mid] < searchingelement:
  			min = mid
  			mid = int((last + mid) / 2)
  		elif array[mid] > searchingelement:
  			last = mid
  			mid = int((mid + min) / 2)
  	return null
  
  		
  if __name__ == '__main__':
  	array = []
  	for i in range(1000000):
  		array.append(i)
  		
  	t0 = time.clock()
  	print binary_search(array, 345676)
  	t1 = time.clock()
  	print "binary_search: " + str(t1-t0)
  
subject: Update binary-search.py