def bsort (A): h,t,n = 0,0,len(A) while h == 0: h = 1 for i in range(n-t-1): if A[i] > A[i+1]: h = 0 A[i] , A[i+1] = A[i+1] , A[i] t += 1 return(A) def BS(A,k,s=0,l=0,h='none'): if s == 1: A = bsort(A) if h == 'none': h = len(A)-1 if h < l: return None else: m = l + (h-l)//2 if A[m] > k: return BS(A,k,0,l,m-1) elif A[m] < k: return BS(A,k,0,m+1,h) else: return m
web page is actually superb.