(list_of_keys, search_key)
return key_comparisons_made
Perform a Linear search.

    Returns the number of comparisons required.
Perform a Linear search.
Perform a Linear search .
def linear_search_count(list_of_keys, search_key):
    """
    Perform a Linear search.

    Returns the number of comparisons required.
    """
    length_of_list = len(list_of_keys)
    if length_of_list == 0:
        print("List of keys not found.")
        return 0

    key_comparisons_made = 0
    search_key_index = 0
    while search_key_index < length_of_list:
        key_comparisons_made += 1
        if list_of_keys[search_key_index] == search_key:
            return key_comparisons_made
        search_key_index += 1

    return key_comparisons_made
def linear_search_count ( list_of_keys , search_key ) : length_of_list = len ( list_of_keys ) if length_of_list == 0 : print ( "List of keys not found." ) return 0 key_comparisons_made = 0 search_key_index = 0 while search_key_index < length_of_list : key_comparisons_made += 1 if list_of_keys [ search_key_index ] == search_key : return key_comparisons_made search_key_index += 1 return key_comparisons_made