敏感词审查

一个一个的审查,来检测这单个字是否在敏感字内

words = ('废物', '66')  # 创建一个敏感词汇库
user_text = input('Please enter a words:')
for words in words: # 遍历敏感词汇库
    # print(words)
    for word in user_text:
        # print(word)
        if word in words: # 判断用户输入的词汇是否有敏感词汇
            user_text = user_text.replace(word, '*') # 将敏感词汇替换成"*"

print(user_text)

但这个代码把我们不想屏蔽的词给屏蔽了,毕竟它是单个遍历,不能要求太多,所以必须将代码改成能识别单词的程序,在进行屏蔽,可以利用正则运算。

发布了18 篇原创文章 · 获赞 3 · 访问量 1059

猜你喜欢

转载自blog.csdn.net/hjh_cos/article/details/103841248