Created
October 4, 2015 12:38
-
-
Save poros/08646064caaf80f33763 to your computer and use it in GitHub Desktop.
Find the first occurrence in a list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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