import random
names =["Or","Yana","Amir","Roee","Noa","Gal","Barak",
"Rina","Tal","Lielle","Shady","Yuval"]
students_list =[[ name , random.randint (2*10**7 ,6*10**7)] \
for name in names ] # leading digits are 2 ,3 ,4 ,5
def sequential_search(key,lst):
""" sequential search from lst[0] till last lst element
lst need not be sorted for sequential search to work"""
for elem in lst:
if elem[0]==key:
return elem
# we get here when the key is not in the list
print(key, "not found") # For debugging purposes!
return None
def sequential_search_back(key,lst):
""" sequential search from last lst element to first element
lst need not be sorted for sequential search to work"""
for elem in lst[::-1]: # goes over elements in reversed lst
if elem[0]==key:
return elem
# we get here when the key is not in the list
print(key, "not found")
return None
def binary_search(key,lst):
""" iterative binary search
lst better be sorted for binary search to work"""
n=len(lst)
left=0
right=n-1
outcome=None # default value
while left<=right:
middle=(right+left)//2
if key==lst[middle][0]: # item found
outcome=lst[middle]
break # gets out of the loop if key was found
elif key