Skip to content

Instantly share code, notes, and snippets.

@poros
Created October 4, 2015 12:38
Show Gist options
  • Save poros/08646064caaf80f33763 to your computer and use it in GitHub Desktop.
Save poros/08646064caaf80f33763 to your computer and use it in GitHub Desktop.
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!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment