综合练习:英文词频统计

Posted on 2018-03-25 22:34  170何强  阅读(136)  评论(0编辑  收藏  举报
song = '''
    Take a deep breath in the mirror,
he didn't like it when I wore high heels but I do.

Turn the lock and put my headphones on,
he always said he didn't get this song but I do. I do.

Walked in expecting you'd be late
but you got here early and you stand and wait I walk to you.

You pulled my chair out and helped me in,
and you don't know how nice that is but I do.

And you throw your head back laughing like a little kid.
I think it's strange that you think I'm funny cause he never did.
I've been spending the last eight months
thinking all love ever does is break, and burn, and end.
But on a Wednesday, in a cafe...I watched it begin again.
 '''

delet = list(''',.?!’:"“”-%$''')
for i in delet:
    song = song.replace(i, ' ')
song = song.lower().split()
word = {}
for i in song:
    count = song.count(i)
    word[i] = count
words = '''
a an the in on to at and of is was are were i he she you your they us their our it or for be too do no 
that s so as but it's
'''
prep = words.split()
for i in prep:
    if i in word.keys():
        del (word[i])
word = sorted(word.items(), key=lambda item: item[1], reverse=True)
for i in range(10):
    print(word[i])

结果截图:

Copyright © 2024 170何强
Powered by .NET 8.0 on Kubernetes