阶段作业1:完整的中英文词频统计

hh = '''You're on the phone with your girlfriend
She's upset
She's going off about something that you said
'Cause she doesn't get your humor like I do
I'm in my room
It's a typical Tuesday night
I'm listening to the kind of music she doesn't like
And she'll never know your story like I do
But she wears short skirts
I wear T-shirts
She's cheer captain
And I'm on the bleachers
Dreaming about the day when you wake up
And find that what you're looking for has been here the whole time
If you can see I'm the one who understands you
Been here all along so why can't you see
You belong with me
You belong with me
Walkin' the streets with you and your worn-out jeans
I can't help thinking this is how it ought to be
Laughing on a park bench thinking to myself
Hey isn't this easy
And you've got a smile that could light up this whole town
I haven't seen it in a while since she brought you down
You say you're fine
I know you better then that
Hey what you doing with a girl like that
She wears high heels
I wear sneakers
She's cheer captain and I'm on the bleachers
Dreaming about the day when you wake up
And find that what what you're looking for has been here the whole time
If you can see that I'm the one who understands you
Been here all along so why can't you see
You belong with me
Standing by and waiting at your back door
All this time how could you not know
Baby you belong with me
You belong with me
Oh I remember you drivin' to my house in the middle of the night
I'm the one who makes you laugh
When you know you're about to cry
And I know your favorite songs
And you tell me about your dreams
I think I know where you belong
I think I know it's with me
Can't you see that I'm the one who understands you
Been here all along so why can't you see
You belong with me
Standing by and waiting at your back door
All this time
How could you not know
Baby you belong with me
You belong with me
You belong with me
Have you ever thought just maybe
You belong with me
You belong with me'''.lower()
a=''',.?!'''
for i in a:
    listhh = hh.replace(i,' ')
listhh = listhh.strip()
listhh = listhh.split()

listhhSet = set(listhh)
print(listhhSet)
ex = {'a','the','and','for','this','at','to','do','by','get','on','who','with'}
allset = listhhSet - ex
print(allset)


dic={}
for j in allset:
    dic[j] = listhh.count(j)
wen=list(dic.items())
print(wen)

def wwe(elem):
    return elem[1]
wenlist = sorted(dic.items(),key=wwe,reverse=True)
print(wenlist)


for k in range(20):
    print(wenlist[k])

  

import jieba
f=open('fuqin1.txt','r',encoding='utf-8')
life=f.read()
f.close()
lifelist=list(jieba.cut(life))
lifedict={}
for word in lifelist:
    if len(word)==1:
        continue
    else:
        lifedict[word]=lifedict.get(word,0)+1

wordlist=list(lifedict.items())
wordlist.sort(key=lambda x:x[1],reverse=True)

for a in range(15):
    print(wordlist[a])

  

 

转载于:https://www.cnblogs.com/SpaldingWen/p/9818923.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值