def binary_search(list, item): low = 0 high = len(list) - 1 while low <= high: # 结束条件 mid = (low + high) / 2 # 就检查中间的元素 guess = list[mid] if guess == item: return mid if guess > item: # 猜的数字大了 high = mid - 1 else: low = mid + 1 return None