Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gcrsaldanha/dfdf007cc015a4a36ccddef88def617a to your computer and use it in GitHub Desktop.
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
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('fake@email.com')
print('Done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment