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

    song = '''
        Don't need permission
      Made my decision to test my limits
      Cause it's my business god as my witness
      Start what I finished
      Don't need no hold up
      Taking control of this kind of moment
      I'm locked and loaded
      Completely focused my mind is open
      All that you got skin to skin oh my god
      Don't ya stop boy
      Something 'bout you makes me feel like a dangerous woman
      Something 'bout something 'bout something 'bout you
      Makes me wanna do things that I shouldn't
      Something 'bout something 'bout something 'bout
      Nothing to prove and I'm bulletproof and
      Know what I'm doing
      The way we're movin' like introducing us to a new thing
      I wanna savor save it for later
      The taste of flavor cause I'm a taker
      Cause I'm a giver it's only nature
      I live for danger
      All that you got skin to skin oh my god
      Don't ya stop boy
      Something 'bout you makes me feel like a dangerous woman
      Something 'bout something 'bout something 'bout you
      Makes me wanna do things that I shouldn't
      Something 'bout something 'bout something 'bout you
      All girls wanna be like that
      Bad girls underneath like that
      You know how I'm feeling inside
      Something 'bout
      All girls wanna be like that
      Bad girls underneath like that
      You know how I'm feeling inside
      Something 'bout something 'bout
      Something 'bout you makes me feel like a dangerous woman
      Something 'bout something 'bout something 'bout you
      Makes me wanna do things that I shouldn't
      Something 'bout something 'bout something 'bout you
      All girls wanna be like that
      Bad girls underneath like that
      You know how I'm feeling inside
      Something 'bout something 'bout
      All girls wanna be like that
      Bad girls underneath like that
      You know how I'm feeling inside
      Something 'bout something 'bout
      Yeah there's something 'bout you boy
      Yeah there's something 'bout you boy
      Yeah there's something 'bout you boy
      Something 'bout something 'bout something 'bout you
      Yeah there's something 'bout you boy
      Yeah there's something 'bout you boy
      Yeah there's something 'bout you boy
      Something 'bout something 'bout something 'bout you
     '''
    sep=''',.?!:'-'''
    for c in sep:
        song = song.replace(c,'')
    wordList = song.lower().split()
    
    wordDict={}
    '''wordSet=set(wordList)
    for w in wordSet:
        wordDict[w]=wordList.count(w)
    '''
    for w in wordList:
        wordDict[w]=wordDict.get(w,0)+1
        dictList = list(wordDict.items())
        dictList.sort(key=lambda x:x[1],reverse=True)
    
        for w in dictList:
            print(w)

  • 相关阅读:
    vector详解
    笔记
    积木大赛
    codevs 1086 栈(Catalan数)
    不要把球传我
    同余方程 (codevs1200)
    最小集合
    数的计算
    产生数
    逃跑的拉尔夫
  • 原文地址:https://www.cnblogs.com/guoyaowen/p/8649617.html
Copyright © 2011-2022 走看看