Created
November 14, 2012 06:28
-
-
Save max-giro/4070638 to your computer and use it in GitHub Desktop.
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
# This works | |
def isWordIn(word, text): | |
for sign in string.punctuation: | |
if (sign in text): | |
text = text.replace(sign, '') | |
print(text) | |
words = (text.lower()).split() | |
print(words) | |
return word in words | |
isWordIn('ciao', 'Ciao, come stai') | |
Ciao come stai | |
['ciao', 'come', 'stai'] | |
True |
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
# This fails | |
class WordTrigger(Trigger): | |
"""Abstract class for word triggers""" | |
def __init__(self, word): | |
self.word = word | |
def isWordIn(self, text): | |
for sign in string.punctuation: | |
if (sign in text): | |
text = text.replace(sign, '') | |
words = (text.lower()).split() | |
return self.word in words |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment