yNdots
需要及时鞭策的测试汪
#coding:utf-8
#!/usr/bin/python2.6


def statistic_eng_text():
    '''统计出英文文档中高频词汇'''
    cnt = Counter()
    np = os.path.join(get_project_path(),'doc','jack lodon.txt')
    ff = open(np,'r')
    words = ff.read()
    format_text = re.split('[\s\ \\,\;\.\!\n]+',words)

    for w in format_text:#比较的时候注意了大小写,其中有一个 the是以大写字母开始的,所以在notepad中统计出来了,而在代码中没有统计出来

        cnt[w.lower()] += 1#这里需要把单词进行一个转换,避免大小写导致的不匹配
    print cnt.most_common(5)

if __name__ == '__main__':
    statistic_eng_text()

  

posted on 2017-07-14 18:31  一条特立独行的狗  阅读(240)  评论(0编辑  收藏  举报