def word_count(message, word):
"""
Computes the number of times a word appears in a message
(case-insensitive).
Args:
message: A Message object.
word: A string with no spaces.
Returns:
An int representing the number of times word (case-insensitive)
appears in the text of message split by spaces.
"""
if ' ' in word:
raise ValueError('word cannot contain spaces')
lowercase_tokens = [token.lower() for token in nltk.word_tokenize(message.text)]
return lowercase_tokens.count(word.lower())
conversation.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录