python敏感词字典

1710人浏览 / 0人评论

一、文件铭感词字典

user_input=input('Leave your comments:  ')
for filter_word in open('filtered_words.txt'):
    fw=filter_word.rstrip()
    if fw in user_input:
        fw_len=len(fw)
        user_input=user_input.replace(fw,'*'*fw_len)  #将user_input在原处进行修改,进行下一次循环查找。

else:
           print(user_input)

二、普通铭感词字典

 

li = ["苍井空", "东京热", "武藤兰", "波多野结衣"]
comment_list = []
comment = input('请输入您的评论:')
for word in li:
    if word in comment:
        comment = comment.replace(word,'*'*len(word))
comment_list.append(comment)
print(comment_list)

全部评论