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

    song = '''
        Take a deep breath in the mirror,
    he didn't like it when I wore high heels but I do.
    
    Turn the lock and put my headphones on,
    he always said he didn't get this song but I do. I do.
    
    Walked in expecting you'd be late
    but you got here early and you stand and wait I walk to you.
    
    You pulled my chair out and helped me in,
    and you don't know how nice that is but I do.
    
    And you throw your head back laughing like a little kid.
    I think it's strange that you think I'm funny cause he never did.
    I've been spending the last eight months
    thinking all love ever does is break, and burn, and end.
    But on a Wednesday, in a cafe...I watched it begin again.
     '''
    
    delet = list(''',.?!’:"“”-%$''')
    for i in delet:
        song = song.replace(i, ' ')
    song = song.lower().split()
    word = {}
    for i in song:
        count = song.count(i)
        word[i] = count
    words = '''
    a an the in on to at and of is was are were i he she you your they us their our it or for be too do no 
    that s so as but it's
    '''
    prep = words.split()
    for i in prep:
        if i in word.keys():
            del (word[i])
    word = sorted(word.items(), key=lambda item: item[1], reverse=True)
    for i in range(10):
        print(word[i])

    结果截图:

  • 相关阅读:
    db2新添用户
    merge的用法
    oracle常用命令
    oracle建用户
    获得当前时间的PRO
    全部快捷方式图标变成LNK文件怎么办
    随机生成数据的三种方法
    db2查看表空间
    db2疑难解决
    AVG()和to_date()函数的使用
  • 原文地址:https://www.cnblogs.com/170he/p/8647457.html
Copyright © 2011-2022 走看看