zoukankan      html  css  js  c++  java
  • 每天一个小程序—0012题(敏感词替换)

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

     1 #!/usr/bin/env python
     2 
     3 filtered = []
     4 
     5 def get_filtered_words():
     6     f = open('test.txt')
     7     for word in f.readlines():
     8         if '
    ' in word:
     9             filtered.append(word[:-1])
    10         else:
    11             filtered.append(word)
    12     print(filtered)
    13 
    14 def input_check():
    15     while True:
    16         text = input('请输入内容:')
    17         for word in filtered:
    18             if word in text:
    19                 str = ''
    20                 for i in range(len(word)):
    21                     str += '*'
    22                 text = text.replace(word, str)
    23         print(text)
    24 
    25 if __name__ == '__main__':
    26     get_filtered_words()
    27     input_check()

  • 相关阅读:
    倒计时功能的实现
    getElementsByClassName
    模拟滚动条
    display:table-cell
    gulp相关知识(2)
    gulp相关知识(1)
    移动端的网页试做
    关于移动端的布局
    伪类before和after
    简单时钟——css3
  • 原文地址:https://www.cnblogs.com/zyb993963526/p/8359908.html
Copyright © 2011-2022 走看看