We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ec4e4b9 commit 87bef18Copy full SHA for 87bef18
2 files changed
Drake-Z/0012/0012.py
@@ -0,0 +1,31 @@
1
+#!/usr/bin/env python3
2
+# -*- coding: utf-8 -*-
3
+
4
+'第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。'
5
6
+__author__ = 'Drake-Z'
7
8
+import os
9
+import re
10
11
+def filter_word(a):
12
+ sensitive = False
13
+ strs = '**'
14
+ f = open('filtered_words.txt', 'r', encoding = 'utf-8').readlines()
15
+ for i in f:
16
+ i = i.strip()
17
+ b = re.split(r'%s' % (i), a)
18
+ if len(b) > 1:
19
+ c = i
20
+ sensitive = True
21
+ else:
22
+ pass
23
+ if sensitive == True:
24
+ b = re.split(r'%s' % (c.strip()), a)
25
+ print(strs.join(b))
26
27
+ print(a)
28
+ return 0
29
30
+z = input('请输入:')
31
+filter_word(z)
Drake-Z/0012/filtered_words.txt
@@ -0,0 +1,11 @@
+北京
+程序员
+公务员
+领导
+牛比
+牛逼
+你娘
+你妈
+love
+sex
+jiangge
0 commit comments