poros
10/4/2015 - 12:38 PM

Find the first occurrence in a list

Find the first occurrence in a list

for r in restaurants:
    if r.score >= 4.5:
        return r.name
return "let's cook!"


first = next((r.name for r in restaurants if r.score > 4.5), "let's cook!")