Skip to content

Instantly share code, notes, and snippets.

@max-giro
Created November 14, 2012 06:28
Show Gist options
  • Save max-giro/4070638 to your computer and use it in GitHub Desktop.
Save max-giro/4070638 to your computer and use it in GitHub Desktop.
# 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 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