1.需求与分析: 特殊符号的处理:通过空格把特殊符号替换 2.源码实现: def getText(): txt = open(r"../lib/words_count.txt", "r", encoding="utf-8").read() txt = txt.lower() for ch in '''~!`@#$%^&*()_+}{[]"';:-=*,.:|\ ''': # 清除特殊字符 txt = txt.replace(ch, " ") return txt def main(): hamletTxt = getText()