【发布时间】:2018-05-07 01:05:13
【问题描述】:
无论标点符号如何,程序都能正确识别单词。我无法将其集成到 spam_indicator(text) 中。
def spam_indicator(文本):
text=text.split()
w=0
s=0
words=[]
for char in string.punctuation:
text = text.replace(char, '')
return word
for word in text:
if word.lower() not in words:
words.append(word.lower())
w=w+1
if word.lower() in SPAM_WORDS:
s=s+1
return float("{:.2f}".format(s/w))
第二个块是错误的。我正在尝试删除标点符号以运行该功能。
【问题讨论】:
标签: python string replace punctuation