python 实现敏感词屏蔽小程序

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

代码实现主体:

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

运行结果:

原文地址:https://www.cnblogs.com/wolfshining/p/7647247.html