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

    结果截图:

  • 相关阅读:
    PHP0002:PHP基础1
    NodeJS_0001:关于install的方式
    JN_0018:运行窗口不显示
    事务、事务操作、事务隔离级别
    MySQL 常见的两种存储引擎
    8:二叉树的下一个节点
    链表
    文件压缩
    MapReduce--Shuffle原理
    volatile关键字
  • 原文地址:https://www.cnblogs.com/170he/p/8647457.html
Copyright © 2011-2022 走看看