Sobes.tech
Junior — Senior

Анализ кода: поиск проблем в реализации get_first_matching_object

livecode

Task condition

It is necessary to review the provided function and identify all its shortcomings. The function get_first_matching_object should return the first element from the given list that satisfies the predicate condition.


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