Sequential Search

Write a Python program for sequential search

In computer science, linear search or sequential search is a method for finding a particular value in a list that checks each element in sequence until the desired element is found or the list is exhausted. The list need not be ordered.

def sequential_search(list_items, item):

    ind = 0
    found = False

    while ind < len(list_items) and not found:
        if list_items[ind] == item:
            found = True
        else:
            ind = ind + 1

    return found, ind
mylist = [1,5,2,7,4,8,10,12,4]
sequential_search(mylist, 7)
(True, 3)
sequential_search(mylist, 4)
(True, 4)