Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- sorted_list = [i + randint(0,9) for i in range(0,100,10)]
- print (sorted_list)
- def binary_search(sorted_list, value):
- left = 0
- right = len(sorted_list) - 1
- while left <= right:
- mid = int((left + right)/2)
- if sorted_list[mid] > value:
- right = mid - 1
- elif sorted_list[mid] < value:
- left = mid + 1
- else:
- return mid
- return False
- print(binary_search(sorted_list,96))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement