Python-二分法
在数组中查找符合的数字,并返回序列号
def find(list, item):
low =0
hith =len(list)-1
while low <= hith:
mid =int((low + hith) /2)
if list[mid] == item:
return mid
if list[mid] < item:
low = mid +1
else:
hith = hith -1
return None
list = [1,2,3,4,5,6,7,8,9]
item =7
print(find(list, item))