1. 打开文件,将所有字符读入list:s 2. 使用正则表达式,以非英文字符为间隔符,切片,生成一个以单词为基本元素的list 3.由于原先非字母可能连续,故生成的list可能存在空单词,所以需要去除空串 4.全部转成小写,并排序。 5. 将单词顺次存入dict,如果单词存在,则个数加一,如果不存在,则将此单词存入dict,个数设置为...
这篇文章主要介绍了Python统计纯文本文件中英文单词出现个数的方法,结合实例形式总结分析了Python针对文本文件的读取,以及统计文本文件中英文单词个数的4种常用操作技巧,需要的朋友可以参考下: 第一版:效率低 # -*- coding:utf-8 -*- #!python3 path = 'test.txt' with open(path,encoding='utf-8',newline...
1 memories, 1 in 1 without 1 like 1 beneficial 1 up, 1 unable 1 away 1 flies 1 goes 1 a 1 have 2 away, 1 mind, 1 focus 1 principle, 1 hear 1 to 1 the 7 years 1 busy 1 souls, 1 indulge 1 第四版:使用Counter统计: # -*- coding:utf-8 -*- #!python3 import collections...
unable to hear the voices of the soul. As time goes by, childhood away, we grew up, years away a lot of memories, once have also eroded the bottom of the childish innocence, we regardless of the shackles of mind, indulge in the world buckish, focus on the beneficial principle, we ha...