综合练习:词频统计
Posted 125叶胜轩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了综合练习:词频统计相关的知识,希望对你有一定的参考价值。
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])
以上是关于综合练习:词频统计的主要内容,如果未能解决你的问题,请参考以下文章