二分查找的条件是必须是排好的数字
"""二分查找"""
def binary_searhc(arr, target):
n = len(arr)
left = 0
right = n-1
while left <= right :
mid = (left + right)//2
if arr[mid] < target:
left = mid + 1
elif arr[mid] > target:
right = mid - 1
else:
print(mid)
return True
return False
if __name__ == '__main__':
l = [1,2,3,4,6,8]
if binary_searhc(l,6):
print("ok")