9.26

1.读入待分析的字符串

fo=open('test.txt','w')
fo.write('''All the times that you rain on my parade
And all the clubs you get in using my name
You think you broke my heart
Ohhh girl for goodness sake
You think I'm crying
Oh my ohhh, well I ain't!
And I didn't wanna write a song
'Cause I didn't want anyone thinking I still care, I don't
But, you still hit my phone up
And baby I be moving on
And I think you should be somethin' I don't wanna hold back
Maybe you should know that
My mama don't like you and she like's everyone''')
fo=close()

2.分解提取单词

news=news.lower()
for i in ',!'':
    news=news.replace(i,' ')
words=sorry.split(' ')
print(words)

3.计数字典

4.排除语法型词汇

dic={}
words.sort()
d=set(words)
d=d-exc
for i in d:
    dic[i]=words.count(i)

5.排序

6.输出TOP(20)

wc=list(dic.items())
wc.sort(key=lambda x:x[1],reverse=True)#排序
for i in range(20):
    print(wc[i])

 

转载于:https://www.cnblogs.com/chenyanxi123/p/7597321.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值