二分查找
data = [1,7,17,18,27,29,30,35,35,39,41,63,78,82,82,91,92]
def get(data_list,target):
left = 0 #起始
right = len(data_list)-1 #终点 因有起始位置所以要减一
mid = int((left+right)/2) #中间位置
while left <= right: #循环
if data_list[mid] == target:
print(mid)
break
elif data_list[mid] > target:
left = mid - 1
elif data_list[mid] < target:
right = mid + 1
else:
print('没有这个数')
if __name__ == '__main__':
get(data, 39)