1. text = input('请输入你要处理的文档:') 2. def stats_text_en(text): 3. text=text.replace('!',' ') #面对待处理的文档,没办法把可能出现的特殊字符都遍历一边然后替换,如果使用.isalpha()的话会把空格都删掉,该怎么办呢? 4. text=text.lower() 5. text=text.split() 6. dict1={} 7. for i in text: 8. j=text.count(i) 9. dict2={i:j} 10. dict1.update(dict2) 11. dict2=sorted(dict1.items(),key=lambda x:x[1],reverse=True) 12. print(dict2) 13. 14. stats_text_en(text)