Skip to content

Instantly share code, notes, and snippets.

@sin-tanaka
Last active June 6, 2017 07:10
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 sin-tanaka/d12b591163bd70d610c0905999bcbe83 to your computer and use it in GitHub Desktop.
Save sin-tanaka/d12b591163bd70d610c0905999bcbe83 to your computer and use it in GitHub Desktop.
any()を使った少しトリッキーな判定方法 ※見やすいが、短絡評価(short-circuit evaluation)しないので遅い
# all()関数のパターン
MATCH_WORDS = ['fuga', 'foobar']
def is_match(word):
judge = (
word in MATCH_WORDS,
word is 'hoge',
)
return any(judge)
# if文のパターン
MATCH_WORDS = ['fuga', 'foobar']
def is_match(word):
if word in MATCH_WORDS:
return True
elif word is 'hoge':
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment