Search element

Create a function that takes a vector of numbers and a target value as input and returns True if the target value is found in the vector, or False otherwise.

Here, a vector is a one-dimensional Python list of numbers. Match the target with ==. An empty list returns False; keep the input unchanged.

Complete the supplied function in Listing 1. Keep its signature and use the checks below it.

Listing 1: Starter function and supplied checks for search element.
def search_element(vector: list[float], target: float) -> bool:
    # Add code here!
    pass


def test_search_element() -> None:
    # Input list
    vector = [1, 2, 3, 4, 5]

    assert search_element(vector, 3) is True
    assert search_element(vector, 6) is False


test_search_element()

len(values) returns the number of elements, so len([3, 7]) is 2 and len([]) is 0. List indexing starts at 0: [3, 7][0] is 3. An index must refer to an existing element.

assert condition stops the check with an AssertionError when the condition is false.