zoukankan      html  css  js  c++  java
  • 综合练习:英文词频统计

    str = '''
    As long as you love me
    We're under pressure
    Seven billion people in the world trying to fit in
    Keep it together
    Smile on your face even though your heart is frowning
    But hey now you know girl
    We both know it's a cruel world
    But I will take my chances
    As long as you love me
    We could be starving we could be homeless we could be broke
    As long as you love me
    I'll be your platinum I'll be your silver
    I'll be your gold
    As long as you lo lo lo lo ~love me
    As long as youlo lo lo lo ~love me
    I'll be your soldier
    Fighting every second
    Of the day for your dreams girl
    I'll be your Hova you could be my
    Destiny's Child on a scene girl
    So don't stress don't cry we don't need no wings to fly
    Just take my hand
    As long as you love me we could be starving we could be homeless
    We could be broke
    As long as you love me
    I'll be your platinum I'll be your silver
    I'll be your gold
    As long as youlo lo lo lo ~love me
    As long as youlo lo lo lo ~love me
    I don't know if this makes sense but
    You're my hallelujah
    Give me a time and place
    I'll rendezvous it
    I'll fly you to it
    I'll beat you there
    Girl you know I got you
    Us trust
    A couple of things I can't spell without U
    Now we on top of the world 'cause that's just how we do
    Used to tell me sky's the limit
    Now the sky's is our point of view
    Man now we stepping out like
    Oh God
    Cameras point and shoot
    Ask me what's my best side
    I stand back and point at you you you
    The one that I've argue with
    I feel like I need a new girl to be bother with
    But the grass ain't always greener on the other side
    It's green where you water it
    So I know we got issues baby true true true
    But I'd rather work on this with you
    Than go ahead and start with someone new
    As long as you love me
    We could be starving we could be homeless we could be broke
    As long as you love me
    I'll be your platinum I'll be your silver I'll be your gold
    As long as you lo lo lo lo ~love me
    As long as you lo lo lo lo ~love me
    As long as you lo lo lo lo ~love me
    You love me
    You love me
    As long as you love me
    You love me
    You love me
    As long as you love me
    '''
    str = str.replace("'"," ").replace("~","") #将所有分隔符全部替换为空格
    str = str.lower() #将所有大写转换为小写
    str = str.split() #生成单词列表
    dict ={}
    for key in str: #生成词频统计
        dict[key]=dict.get(key,0)+1
    lst = ['as','be','ll','lo','d','s','of','i','could','t','to','on','but','the','a','it']
    for key in lst: #排除语法型词汇,代词、冠词、连词
        del dict[key]
    dict=sorted(dict.items(), key=lambda e: e[1], reverse=True) #排序
    for key in range(10): #输出词频最大TOP10
        print(dict[key])

    结果截图:

  • 相关阅读:
    css数学运算函数 calc(),和css的数学运算
    MySQL设置字段的默认值为当前系统时间
    今天阿里云服务器被挂马wnTKYg挖矿的清理
    linux shell常用命令
    无损扩容,调整Centos6.5服务器分区大小,不适用centos7,centos6.5 调整逻辑卷大小
    添加远程库
    interface 设置默认值
    radio根据value值动态选中
    获取下拉js 具体值
    mysql中int、bigint、smallint 和 tinyint的存储
  • 原文地址:https://www.cnblogs.com/stcy520/p/8647417.html
Copyright © 2011-2022 走看看