File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 北京
2+ 程序员
3+ 公务员
4+ 领导
5+ 牛比
6+ 牛逼
7+ 你娘
8+ 你妈
9+ love
10+ sex
11+ jiangge
Original file line number Diff line number Diff line change 1+ import re
2+ import string
3+
4+
5+ class Filter (object ):
6+
7+ def __init__ (self ):
8+ self .filtered_word_list = []
9+ self .readIO ()
10+
11+ def check (self , word_input ):
12+ res = word_input
13+ for e in self .filtered_word_list :
14+ # print(e)
15+ if e in word_input :
16+ res = res .replace (e , '*' * len (e ))
17+ return res
18+
19+ def readIO (self ):
20+ with open ('demo.txt' , 'r' ) as f :
21+ s_temp = f .readline ().strip ()
22+ while s_temp != "" :
23+ self .filtered_word_list .append (s_temp )
24+ s_temp = f .readline ().strip ()
25+
26+ if __name__ == "__main__" :
27+ filter_obj = Filter ()
28+ while True :
29+ word_input = input ("Enter a sentence to check >" )
30+ str_ans = filter_obj .check (word_input )
31+ print (str_ans )
You can’t perform that action at this time.
0 commit comments