zoukankan      html  css  js  c++  java
  • 文件方式实现完整的英文词频统计实例

    1.读入待分析的字符串

    2.分解提取单词 

    3.计数字典

    4.排除语法型词汇

    5.排序

    6.输出TOP(20)

    str='''We don't talk anymore
    We don't talk anymore
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for? 
    We don't talk anymore 
    Like we used to do
    I just heard you found the one you've been lookin'
    The one you been looking for
    I wish i would've konwn that wasn't me 
    Cause even after all this time i still wonder
    Why i can't move on? 
    Just the way you dance so easliy 
    Don't wanna know 
    The kinda dress you're wearin' tonight
    If he's holdin' onto you so tight
    The way i did before
    I overdosed 
    Should've known your love was game
    Now I can't get'cha out of my brain
    Ooh it's such a shame
    We don't talk anymore
    We don't talk anymore 
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for?
    We don't talk anymore 
    Like we used to do
    I just hope you'r lyin' next to somebody
    Know it's hard to love ya like me
    Must be a good reason that you're gone
    Every now and then
    I think you might want me to come show up your door
    But I'm just too afraid that i'll be worng
    Don't wanna know 
    If you'ra lookin' into her eyes
    If she's holdin' onto you so tight
    The way i did before
    I overdosed
    Should've know your love was a game 
    Now I can't get'cha out of my brain
    Ooh it's such a shame
    We don't talk anymore
    We don't talk anymore
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for? 
    We don't talk anymore
    Like we used to do
    Like we used to do
    Don't wanna know
    The kinda dress you're wearin' tonight
    If he's givin' it to you just right
    The way i did before
    I overdosed
    Should've know your love was a game 
    Now I can't get'cha out of my brain
    Ooh it's such a shame
    We don't talk anymore
    We don't talk anymore
    We don't talk anymore
    Like we used to do 
    We don't laugh anymore
    What was all of it for? 
    We don't talk anymore
    Like we used to do
    We don't talk anymore
    The way did before
    We don't talk anymore
    Ooh 
    Woo
    Ooh it's such a shame
    We don't talk anymore
    '''
    fo=open('D:music.txt','w')
    fo.write(str)
    fo.close
    
    fo=open('D:music.txt','r')
    str=fo.read()
    fo.close()
    for i in ",.?!
    ":
       str=str.replace(i," ")
    str=str.lower()
    str=str.split(" ")
    exc={'to','','of','the','a',"it's",'ooh'}
    words=set(str)
    words=words-exc
    dt={}
    
    for i in words:
       dt[i]=str.count(i)
       
    item=list(dt.items())
    item.sort(key=lambda x:x[1],reverse=True)
    
    for i in range(15):
        print(item[i])

    运行结果:

  • 相关阅读:
    Android为TV端助力 转载:RecyclerView分页加载
    Android 最简单的测试UI卡顿
    Android为TV端助力 使用shared注意事项
    Android为TV端助力 电影栏目移动到底部或者顶部时抖动动画
    Android为TV端助力转载:码农小阿飞(SpannableString)
    Android为TV端助力 监听APK卸载,替换,完成的广播
    Android 为TV端助力
    Android为TV端助力 进制互相转换
    Android为TV端助力linux命令
    Android为TV端助力 集成第三方播放器,实现全屏播放
  • 原文地址:https://www.cnblogs.com/Naiky/p/7595125.html
Copyright © 2011-2022 走看看