综合练习:英文词频统计

  1. 词频统计预处理
  2. 下载一首英文的歌词或文章
  3. 将所有,.?!’:等分隔符全部替换为空格
  4. 将所有大写转换为小写
  5. 生成单词列表
  6. 生成词频统计
  7. 排序
  8. 排除语法型词汇,代词、冠词、连词
  9. 输出词频最大TOP10
str='''
Every night in my dreams
I see you,I feel you
That is how I know you go on
Far across the distance
And spaces between us
You have come to show you go on
Near far
Wherever you are
I believe
That the heart does go on
Once more you open the door
And you're here in my heart
And my heart will go on and on
Love can touch us one time
And last for a lifetime
And never let go till we're gone
Love was when I loved you
One true time I hold to
In my life well always go on
Near far
Wherever you are
I believe
That the heart does go on
Once more you open the door
And you're here in my heart
And my heart will go on and on
you're here
There's nothing I fear
And I know
That my heart will go on
We'll stay forever this way
You are safe in my heart
And my heart will go on and on
'''

#逗号和略写   , '
sym=list("',")
for i in sym:
    str=str.replace(i," ")
#小写
str=str.lower()
#按空格分裂单词
str=str.split()
dictionary=dict()
#单词和个数存到字典中
for i in str:
    dictionary[i]=str.count(i)

#语法词删去
pron = ["for", "to", "the", "and", "of", "in","that","have","has","a","can","not"]
for i in pron:
    if i in dictionary.keys():
        del dictionary[i]

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

 

结果:

 

 

转载于:https://www.cnblogs.com/1103a/p/8649996.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值