python 算法 一
- 二分查找算法
def list_search(l,v): left = 0 right = len(l) -1 while left <= right: mid = (left + right) // 2 if l[mid] == v: return mid elif l[mid] < v: left = mid +1 else: right = mid -1 else: return None l = list(range(100)) s = list_search(l,50) print(s)