首页 > 其他 > 详细

综合练习:词频统计

时间:2018-03-26 15:05:52      阅读:197      评论:0      收藏:0      [点我收藏+]
song = ‘‘‘
An empty street,An empty house,A hole inside my heart,Im 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,Im 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 = ‘‘‘
im 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])

技术分享图片
 

 

综合练习:词频统计

原文:https://www.cnblogs.com/liangyao111/p/8650325.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!