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

综合练习:英文词频统计

时间:2018-03-26 12:29:12      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:key   大小   过渡   image   lambda   分解   英文   综合   one   

#coding=utf-8

song=‘‘‘
Skies,where the blue birds fly,
Clouds where the people place their souls on to.
Brighter,the sunshines that go through my tears,
like searching for what heals my sorrows,
Cry,when the twilights come,
Rise,when the peoples prayers melt in to.
one,to where wed been together in the sphere.
Im searching for where you are,my soul,
I dont know how to put my heart belongs to you;
I dont know how to love someone expect for you;
That is all my world to been had you in my life.
Ill call you all the time,
Skies,where the blue birds cry,
Clouds where the people forgot their souls on to,
Brighter,the sunshines that go through my tears,
like searching for what heals my sorrows,
I dont know what was right or wrong for all Ive told you;
I dont know what was true or false that youve said to me;
But its all my love to believe in you in my life.
Ill call you all the time.
‘‘‘
ellipsis_word={,,.,;,:,?,!,-}   #将一些符号替换成空格
for i in ellipsis_word:
    song.replace(i,‘‘)

Capital_word=song.lower().split()   #大小写替换,并分解

Words={}
for i in set(Capital_word):     #设置集合
    Words[i]=Capital_word.count(i)

delete_word={a, too, in, of, will, the, and, are, with, to, said, as, s}
for i in delete_word:        #删除出现的语法过渡词
    if i in Words:
        Words.pop(i)         #移除列表元素

sort_word = sorted(Words.items(), key= lambda d:d[1], reverse = True)  # 排序
for i in range(10):
    print(sort_word[i])

截图:

技术分享图片

 

综合练习:英文词频统计

标签:key   大小   过渡   image   lambda   分解   英文   综合   one   

原文地址:https://www.cnblogs.com/tiankongyiluozhiwu/p/8649770.html

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