目录
需求:
实现:
需求:
给定一个word.txt文件,统计文件中每个英文单词出现的次数,保存在word2.txt中。
实现:
word.txt:

Python2.7下的统计脚本:
import collections
import re
def word_cal():
with open('word.txt','r') as fp:
content = re.split('[,. ]', fp.read())
b = collections.Counter(content)
with open('word2.txt','w') as result_file:
for key,value in b.items():
result_file.write(key+':'+str(value)+'n')
def main():
word_cal()
if __name__ == '__main__':
main()
统计结果保存到word2.txt中:

最后
以上就是追寻口红最近收集整理的关于Python统计.txt文本中每个英文单词个数需求:实现:的全部内容,更多相关Python统计内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复