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

综合练习:英文词频统计

时间:2018-03-25 23:06:08      阅读:296      评论:0      收藏:0      [点我收藏+]

标签:start   like   lov   dict   got   bubuko   gre   rev   without   

str = ‘‘‘
As long as you love me
We‘re under pressure
Seven billion people in the world trying to fit in
Keep it together
Smile on your face even though your heart is frowning
But hey now you know girl
We both know it‘s a cruel world
But I will take my chances
As long as you love me
We could be starving we could be homeless we could be broke
As long as you love me
I‘ll be your platinum I‘ll be your silver
I‘ll be your gold
As long as you lo lo lo lo ~love me
As long as youlo lo lo lo ~love me
I‘ll be your soldier
Fighting every second
Of the day for your dreams girl
I‘ll be your Hova you could be my
Destiny‘s Child on a scene girl
So don‘t stress don‘t cry we don‘t need no wings to fly
Just take my hand
As long as you love me we could be starving we could be homeless
We could be broke
As long as you love me
I‘ll be your platinum I‘ll be your silver
I‘ll be your gold
As long as youlo lo lo lo ~love me
As long as youlo lo lo lo ~love me
I don‘t know if this makes sense but
You‘re my hallelujah
Give me a time and place
I‘ll rendezvous it
I‘ll fly you to it
I‘ll beat you there
Girl you know I got you
Us trust
A couple of things I can‘t spell without U
Now we on top of the world ‘cause that‘s just how we do
Used to tell me sky‘s the limit
Now the sky‘s is our point of view
Man now we stepping out like
Oh God
Cameras point and shoot
Ask me what‘s my best side
I stand back and point at you you you
The one that I‘ve argue with
I feel like I need a new girl to be bother with
But the grass ain‘t always greener on the other side
It‘s green where you water it
So I know we got issues baby true true true
But I‘d rather work on this with you
Than go ahead and start with someone new
As long as you love me
We could be starving we could be homeless we could be broke
As long as you love me
I‘ll be your platinum I‘ll be your silver I‘ll be your gold
As long as you lo lo lo lo ~love me
As long as you lo lo lo lo ~love me
As long as you lo lo lo lo ~love me
You love me
You love me
As long as you love me
You love me
You love me
As long as you love me
‘‘‘
str = str.replace(""," ").replace("~","") #将所有分隔符全部替换为空格
str = str.lower() #将所有大写转换为小写
str = str.split() #生成单词列表
dict ={}
for key in str: #生成词频统计
    dict[key]=str.count(key)
lst = [as,be,ll,lo,d,s,of,i,could,t,to,on,but,the,a,it]
for key in lst: #排除语法型词汇,代词、冠词、连词
    del dict[key]
dict=sorted(dict.items(), key=lambda e: e[1], reverse=True) #排序
for key in range(10): #输出词频最大TOP10
    print(dict[key])

结果截图:

技术分享图片

 

综合练习:英文词频统计

标签:start   like   lov   dict   got   bubuko   gre   rev   without   

原文地址:https://www.cnblogs.com/stcy520/p/8647417.html

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