码迷,mamicode.com
首页 > 其他好文 > 详细

英文词频统计

时间:2018-03-28 00:01:58      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:div   hat   lam   ict   ace   key   item   print   ike   

string=‘‘‘
Twinkle, twinkle, little star.
Twinkle, twinkle, little star, how I wonder what you are.
Up above the world so high, like a diamond in the sky.
Twinkle, twinkle, little star, how I wonder what you are.
When the blazing sun is gone, when he nothing shines upon.
The you show your little light, Twinkle, twinkle, little star
Twinkle, twinkle, little star, How I wonder what you are.
Twinkle, twinkle, little star, how I wonder what you are.
‘‘‘

#逗号和略写,.
sym=list(",.")
for i in sym:
string=string.replace(i," ")
#小写
string=string.lower()
#按空格分裂单词
str=string.split()
a1=dict()
#单词和个数存到字典中
for i in string:
a1[i]=string.count(i)
#语法词删去
pron = ["wonder", "are", "a", "up", "he", "is","so","the"]
for i in pron:
if i in a1.keys():
del a1[i]

#按value值大小排序
dictionary=sorted(a1.items(),key=lambda item:item[1],reverse=True)
#输出
for i in range(10):
print(dictionary[i])

英文词频统计

标签:div   hat   lam   ict   ace   key   item   print   ike   

原文地址:https://www.cnblogs.com/XiaoFengLuo/p/8660764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!