1. 程式人生 > >python 實現敏感詞屏蔽小程序

python 實現敏感詞屏蔽小程序

Coding blog pen 程序 odi bsp 代碼 屏蔽 技術分享

有一個文件,裏面有一些敏感詞匯,如果輸入這些詞,就用**代替,然後輸出。
敏感詞匯
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 實現敏感詞屏蔽小程序