Junior — Senior
Finding the first element that satisfies the condition
livecode
Task condition
Code review. Assess the correctness of implementation, the safety of using generators, and potential issues with mutable default arguments.
def get_first_matching_object(cond, items=[]):
candidates = (obj for obj in items if cond(obj))
if candidates:
result = candidates[0]
return result
else:
return None