def recode(): with open('a.txt', 'rb') as f: word = f.readlines() t = input('> ') # 输入需识别的文字 for i in word: a = i.decode('utf-8').strip() # 转化为unicode if a in t: # 如果文字中含有敏感词 b = str(t).replace(a, '*') # 将敏感词替换为* t = b # 被替换后的文字 print(t) recode()
敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,
最新推荐文章于 2024-05-10 00:07:31 发布