英文词频统计

str='''You were the shadow to my light

Did you feel us

Another start You fade away

Afraid our aim is out of sight

Wanna see us Alive

Where are you now

Where are you now

Where are you now

Was it all in my fantasy

Where are you now

Were you only imaginary

Where are you now Atlantis

Under the sea Under the sea

Where are you now

Another dream

The monsters running wild inside of me

I'm faded I'm faded

So lost I'm faded

These shallow waters never met

What I needed I'm letting go

A deeper dive

Eternal silence of the sea

I'm breathing Alive

Where are you now

Where are you now

Under the bright

But faded lights

You've set my heart on fire

Where are you now

Where are you now

Where are you now

Where are you now

Where are you now

Atlantis Under the sea

Under the sea

Where are you now

Another dream

The monster running wild inside of me

I'm faded I'm faded

So lost I'm faded'''


#把标点符号用空格替换
str=str.replace(",","").replace(".","").replace("?","").replace("'","").replace(":","").replace('"',"")
str=str.lower() #将字符串转小写
str=str.split() #以空格划分每个单词
ls=list(str) #单词列表
set=set(ls) #列表转集合去重
list1=list(set) #再把集合转成列表作为列表合并
list2=[] #建立个空列表,用来存放每个单词出现的次数
for i in set:
list2.append(str.count(i)) #统计各单词出现次数
dict=dict(zip(list1,list2)) #将单词列表与对应频数组成字典

#去掉一些没意义的单词
list3=['for','the','and','to','of','a','in','xi','on','have','is','by','than']
for i in list3:
del dict[i]
dict2=sorted(dict.items(), key=lambda x: x[1], reverse=True)

for i in range(10): #输出词频top10
print(dict2[i])

转载于:https://www.cnblogs.com/Molemole/p/8645471.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值