综合练习:词频统计

song = '''
An empty street,An empty house,A hole inside my heart,I'm all alone,The rooms are getting smaller,I wonder how,I wonder why,I wonder where they are,The days we had,The songs we sang together,Oh yeah,And oh my love,I'm holding on forever,Reaching for a love that seems so far,So i say a little prayer,And hope my dreams will take me there,Where the skies are blue to see you once again, my love,Over seas and coast to coast,To find a place i love the most,Where the fields are green to see you once again, my love
'''

wordlist1 = song.replace('',' ').lower().split()
wordlist2 = song.split()

c = {}
for i in wordlist2:
    count = wordlist1.count(i)
    c[i] = count

word = '''
i'm you and the an a my i are
'''
wordlist3 = word.split()
for i in wordlist3:
    if i in c.keys():
        del (c[i])

count = sorted(c.items(),key=lambda items: items[1], reverse=True)

for i in range(20):
    print(count[i])


 

 

posted @ 2018-03-26 13:29  091梁耀  阅读(95)  评论(0编辑  收藏  举报