#coding:utf-8
def search(lst,m,n):
def search_upper_bound(lst,key): low = 0 high = len(lst)- 1 if key > lst[high] : return [] if key <= lst[low] : return lst while low < high : mid = (low + high+1) / 2 if lst[mid] < key: low = mid else: high = mid - 1 if lst[low] <= key: return lst[low+1:] def search_lower_bound(lst,key): low = 0 high = len(lst)- 1 if key <= lst[low] : return [] if key >= lst[high] : return lst while low < high : mid = (low + high ) / 2 if key < lst[mid]: high = mid else: low = mid +1 if key <=lst[low]: return lst[:low] return list(set(search_upper_bound(lst,m)) & set(search_lower_bound(lst,n))) lst = [3,6,9,10,12,23,56,88] print search(lst,7,55)