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