博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件方式实现完整的英文词频统计实例
阅读量:7170 次
发布时间:2019-06-29

本文共 960 字,大约阅读时间需要 3 分钟。

1.读入待分析的字符串

2.分解提取单词 

3.计数字典

4.排除语法型词汇

5.排序

6.输出TOP(20)

fo=open('dead romance.txt','w')fo.write('''in a rainy nightcan you hear mein a rainy nightcan you help meman,what are you thinking of man,what do you needman,nobody tell you what to doman ,you need somebody to hurtin a rainy nightcan you hear mein a rainy nightcan you help meman,you feel so lonelyman,can you hear the message come from the skyman,you are driving into the rainman,you know it's time to find the preyin a rainy nightcan you hear mein a rainy nightcan you help me''')fo.close()fo=open('dead romance.txt','r')A= fo.read()exc={'the','and','to','of','in','a','for','with',''}for i in ',.?!\n"':    A=A.replace(i,' ')A=A.lower()A=A.split(" ")words=set(A)dic={}keys=set(A)#出现过单词的集合,字典的KEYkeys=keys-excfor i in keys:    dic[i]=A.count(i)w=list(dic.items())w.sort(key=lambda x:x[1],reverse=True)for i in range(20):    print(w[i])fo.close()

 

转载于:https://www.cnblogs.com/lianghaohui123/p/7598950.html

你可能感兴趣的文章
Error: Divergence detected in AMG solver: k
查看>>
Spring学习系列(一) Spring简介
查看>>
Windows绘图和GDI+疑难
查看>>
C#字符串的方法
查看>>
ubuntu搜狗拼音安装
查看>>
小牢骚
查看>>
redis 五种数据结构详解(string,list,set,zset,hash)
查看>>
烤鸡翅
查看>>
XSS(跨站脚本攻击)
查看>>
IT兄弟连 JavaWeb教程 JSP中的注释
查看>>
javascript截取字符串长度
查看>>
常见算法整理
查看>>
Hadoop 2.5.1 + HBase 0.98 单机
查看>>
javascript页面定时跳转
查看>>
结对-英文词频检测10.13
查看>>
在ASP中限制同一表单被多次提交
查看>>
寒假作业1 c题
查看>>
python requests https 访问出错
查看>>
【洛谷 P2042】 [NOI2005]维护数列(自闭记第一期)
查看>>
paramiko远程
查看>>