• 综合练习:英文词频统计


    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])

    结果截图:

  • 相关阅读:
    Linux之基础系统优化
    Linux之shell命令
    Django解决跨域问题
    Django中使用geetest验证
    python2与python3的区别
    一个长得很丑的登录和注册
    Django组件-forms组件
    Django组件-中间件
    cookie、session与用户认证组件
    jquery练习
  • 原文地址:https://www.cnblogs.com/stcy520/p/8647417.html
Copyright © 2020-2023  润新知