# 针对有序列表
def binary_search(lst, value):
left = 0
right = len(lst) - 1
while left <= right:
mid = (left + right) // 2
if lst[mid] == value:
return mid
elif lst[mid] > value:
right = mid - 1
else:
left = mid + 1
else:
return None
# 针对有序列表
def binary_search(lst, value):
left = 0
right = len(lst) - 1
while left <= right:
mid = (left + right) // 2
if lst[mid] == value:
return mid
elif lst[mid] > value:
right = mid - 1
else:
left = mid + 1
else:
return None