Last active
April 28, 2020 12:39
-
-
Save gcrsaldanha/dfdf007cc015a4a36ccddef88def617a to your computer and use it in GitHub Desktop.
A simple snippet of coding showing how to use Python generators and any to avoid extra calls
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
def has_facebook_account(user_email): | |
print('calling Facebook service') | |
return False | |
def has_github_account(user_email): | |
print('calling Github service') | |
return True | |
def has_twitter_account(user_email): | |
print('calling Twitter service') | |
return True | |
def has_social_account(user_email): | |
calls = [ | |
has_facebook_account, | |
has_github_account, | |
has_twitter_account, | |
] | |
return any((call(user_email) for call in calls)) | |
if __name__ == "__main__": | |
print('Checking social media apps...') | |
has_social_account('[email protected]') | |
print('Done!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment