首页 > 编程语言 > 详细

【python小练】0012题

时间:2016-04-08 14:58:22      阅读:262      评论:0      收藏:0      [点我收藏+]

第 0012 题: 敏感词文本文件 filtered_words.txt,里面的内容 和 0011题一样,当用户输入敏感词语,则用 星号 * 替换,例如当用户输入「北京是个好城市」,则变成「**是个好城市」。

 

把上一题的代码改一下就可以咯。

 

Code:

def filtertext(x):
    with open(x, r) as f:
      text = f.read()
    userinput = input(myinput:)
    for i in text.split(\n):
        if i in userinput:
            userinput = userinput.replace(str(i), **len(i))
    print(userinput)

filtertext(word.txt)

 

结果:

myinput:我是住在北京的程序员。
我是住在**的***。

 

【python小练】0012题

原文:http://www.cnblogs.com/liez/p/5367656.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!