Home > Backend Development > Python Tutorial > 布同 统计英文单词的个数的python代码

布同 统计英文单词的个数的python代码

WBOY
Release: 2016-06-06 11:27:38
Original
1231 people have browsed it

word中对于英文单词的统计也很好,大家不妨试试。如果没有安装word,而且你也是程序员的话,那么可以使用我的这段代码。通过测试,word的统计结果是18674,软件的统计结果是18349,相差不到2%,可以作为一个参考。

  代码如下:

代码如下:


# -*- coding: utf-8 -*-

import os,sys
info = os.getcwd() #获取当前文件名称
fin = open(u'谷歌C++编程代码规范.txt')

info = fin.read()
alist = info.split(' ') # 将文章按照空格划分开

fout = open(u'count.txt', 'w')
fout.write('\n'.join(alist)) # 可以通过文本文件的行号同样看到效果
##fout.write('%s' % alist)
fout.close()

allen = len(alist) # 总的单词数
nulen = alist.count('') # 空格的数量
print "words' number is",allen
print "null number is",nulen
print "poor words number is", allen-nulen # 实际的单词数目

fin.close()

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template