Python 字符串关键字过滤

时间:2015-05-10 18:38:48   收藏:0   阅读:193

问题:
把给定字符串中的关键字用与关键字等长的“*”串代替。

 


 

 

Solution:

方法1:

  string 中的 replace 函数

 

方法2:

1 def censor(text, word):
2     words = text.split(word)
3     return ("*"*len(word)).join(words)

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!