综合练习:词频统计
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])
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步