码迷,mamicode.com
首页 > 其他好文 > 详细

综合练习:词频统计

时间:2018-03-26 12:35:17      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:style   and   bubuko   综合   info   body   log   技术分享   eve   

song = ‘‘‘
just colse your eyes,the sun is going down
you‘ll be all right,no one can hurt you now
come morning light ,you and i ’ll be safe and sound
‘‘‘
str1 = song.replace(, ).lower().split()
str2 = song.split()
c = {}
for i in str2:
    count = str1.count(i)
    c[i] = count

word = ‘‘‘
i ’ll you‘ll the 
‘‘‘
str3 = word.split()
for i in str3:
    if i in c.keys():
        del (c[i])

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

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

技术分享图片

综合练习:词频统计

标签:style   and   bubuko   综合   info   body   log   技术分享   eve   

原文地址:https://www.cnblogs.com/TopHin/p/8649768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!