Skip to content

Commit

Permalink
Update and rename Code to 0012.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cw-plus authored Feb 28, 2018
1 parent 80abba2 commit 4ddabc5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 22 additions & 0 deletions 0012.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
# 第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,
则变成「**是个好城市」。
#敏感词语list
path = r'C:\Users\ChaoWang\Desktop\TODO\python\code\filtered_words.txt'
filtered_words = []
with open(path, 'r') as file:
for line in file.readlines():
filtered_words.append(line.strip()) #使用strip()去除空格,取出每一行的单词。#Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)。语法str.strip([chars])

print filtered_words
input1 = raw_input('inputs words:')

input2 = input1.split(" ")

for i in input2:
if i in filtered_words:
input1 = input1.replace(i, r'**')
print (input1)
1 change: 0 additions & 1 deletion Code

This file was deleted.

0 comments on commit 4ddabc5

Please sign in to comment.