zoukankan      html  css  js  c++  java
  • 文件方式实现完整的英文词频统计实例

    题目:可以下载一长篇的英文小说,进行词频的分析。

    1.读入待分析的字符串

    2.分解提取单词 

    3.计数字典

    4.排除语法型词汇

    5.排序

    6.输出TOP(20)

    7.对输出结果的简要说明。

    fo=open('article.txt','w')
    #读入待分析的字符串 
    news=fo.read()

    fo.close()
    #字符串处理
    news.lower()          
    for i in '.,:;?!-_':
        news.replace(i,' ')
    #分解提取单词
    news=news.split(' ')      #排除语法型词汇
    exp={'the','of','and','to','a','in','at','for','with','an','has','that','will','should','is','its','he','have','on','each','during','as'}
    word=set(news)-exp
    #计数字典
    dic={}                     
    for i in word:
        dic[i]=news.count(i)
    news=list(dic.items())
    #排序
    news.sort(key=lambda x:x[1],reverse=True)     
    for i in range(20):
       print(news[i])

     

    由结果可知,是关于G20峰会的内容,国家之间的开会,更好促进国与国之间交流。

  • 相关阅读:
    Linux系统安装
    设计模式的原则
    vue基础
    软考常考题目及解题技巧
    软件设计师
    Wireshark 使用教程
    JVM 调优
    Shell脚本编写
    Linux相关知识
    HTTP缓存机制及原理
  • 原文地址:https://www.cnblogs.com/1244581939cls/p/7602457.html
Copyright © 2011-2022 走看看