python 实现敏感词屏蔽小程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 实现敏感词屏蔽小程序相关的知识,希望对你有一定的参考价值。

有一个文件,里面有一些敏感词汇,如果输入这些词,就用**代替,然后输出。
敏感词汇
dictionary.txt
文件内容:
SB,傻B,傻逼,妈,日,shabi,操,sb,金三胖

代码实现主体:

f = open(dictionary.txt, r, encoding=utf-8)
dic = f.read().split(,)
string = input("请发言:\\n")
for word in dic:
    if word in string:
        count = len(word)
        string = string.replace(word, **count)
print("你说:", string)

运行结果:

技术分享

 


以上是关于python 实现敏感词屏蔽小程序的主要内容,如果未能解决你的问题,请参考以下文章