首页 > 其他 > 详细

英文词频统计

时间:2018-03-27 23:22:38      阅读:219      评论:0      收藏:0      [点我收藏+]

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

英文词频统计

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!