二分查找
def bin_search(array, value): """二分查找""" left = 0 right = len(array) - 1 while left <= right: middle = (left + right) // 2 if array[middle] > value: right -= 1 elif array[middle] < value: left += 1 else: return middle return None array = [1, 2, 3, 4, 5, 6] result = bin_search(array, 6) print(result)