def binarySearch(seq, cmp_func):
 lower = 0
 upper = len(seq)
 while (lower < upper):
  index = ((lower + upper) >> 1)
  diff = cmp_func(seq[index])
  if (diff < 0):
   upper = index
  elif (diff > 0):
   lower = (index + 1)
  else:
   return index
 return None

def binarySearch ( seq , cmp_func ) : lower = 0 upper = len ( seq ) while ( lower < upper ) : index = ( ( lower + upper ) >> 1 ) diff = cmp_func ( seq [ index ] ) if ( diff < 0 ) : upper = index elif ( diff > 0 ) : lower = ( index + 1 ) else : return index return None
search a value in a sequence using binary search .