In [ ]:
#Search Pseudo-Code
#inputs list and value
#set counter to 0
#iterate through the list of numbers
#start a counter, while iterating through the list
#if the value is in the list, return the index generated with the counter
#else it is not in the list, return thast the value is not in the list
#if it is, return the current index
In [ ]:
#or: binary search
In [65]:
def finding(lst, value):
index = 0
for item in lst:
if value == lst[index]:
print("The value is in the list, and it's index is: " + str(index) + '.')
#break
if value not in lst:
print("The value is not in the list.")
break
else:
index += 1
In [66]:
import random
value1000 = random.randint(0,1000)
In [70]:
%time
lst10 = [random.randint(0,1000) for r in range(10)]
finding(lst, value1000)
In [71]:
%time
lst100 = [random.randint(0,1000) for r in range(100)]
finding(lst100, value1000)
In [72]:
%time
lst1000 = [random.randint(0,1000) for r in range(1000)]
finding(lst1000, value1000)