this is pure python implementation of sentinel linear search algorithm for doctests run following command python m doctest v sentinellinearsearch py or python3 m doctest v sentinellinearsearch py for manual testing run python sentinellinearsearch py pure implementation of sentinel linear search algorithm in python param sequence some sequence with comparable items param target item value to search return index of found item or none if item is not found examples sentinellinearsearch0 5 7 10 15 0 0 sentinellinearsearch0 5 7 10 15 15 4 sentinellinearsearch0 5 7 10 15 5 1 sentinellinearsearch0 5 7 10 15 6 pure implementation of sentinel linear search algorithm in python param sequence some sequence with comparable items param target item value to search return index of found item or none if item is not found examples sentinel_linear_search 0 5 7 10 15 0 0 sentinel_linear_search 0 5 7 10 15 15 4 sentinel_linear_search 0 5 7 10 15 5 1 sentinel_linear_search 0 5 7 10 15 6
def sentinel_linear_search(sequence, target):
    
    sequence.append(target)

    index = 0
    while sequence[index] != target:
        index += 1

    sequence.pop()

    if index == len(sequence):
        return None

    return index


if __name__ == "__main__":
    user_input = input("Enter numbers separated by comma:\n").strip()
    sequence = [int(item) for item in user_input.split(",")]

    target_input = input("Enter a single number to be found in the list:\n")
    target = int(target_input)
    result = sentinel_linear_search(sequence, target)
    if result is not None:
        print(f"{target} found at positions: {result}")
    else:
        print("Not found")