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

    结果截图:

  • 相关阅读:
    Zookeeper----1.基础知识
    UML图
    VUE入门3---axios
    VUE入门2---vue指令
    谁先执行?props还是data或是其他? vue组件初始化的执行顺序详解
    vue双向绑定原理分析
    HTML/CSS -- 浏览器渲染机制
    vue工作原理分析
    导入导出需求整理
    .NET 异步详解
  • 原文地址:https://www.cnblogs.com/170he/p/8647457.html
Copyright © 2011-2022 走看看