>  기사  >  백엔드 개발  >  布同 统计英文单词的个数的python代码

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

WBOY
WBOY원래의
2016-06-06 11:27:381194검색

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()

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.