Sobes.tech
Junior — Senior

Determining the first suitable element using the assignment operator

livecode

Task condition

It is necessary to check how the function get_first_matching_object, which uses the assignment operator :=, works. You need to understand what value will be returned if you pass it the list [1, 2, 3, 4] and the predicate lambda x: x == 1.

def get_first_matching_object(predicate, objects=[]):
    for obj in objects:
        if object := predicate(obj):
            return object
    return None

get_first_matching_object(lambda x: x == 1, [1, 2, 3, 4])  # → ?