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

    song ='''
    There's a girl in my mirror
    I wonder who she is
    Sometimes I think I know her
    Sometimes I really wish I did
    But there's a story in her eyes
    Lullabies and goodbyes
    When she’s lookin’ back at me
    I can tell her heart is broken easily
    ‘Cause the girl in my mirror
    Is cryin’ tonight
    And there's nothing I can tell her
    To make her feel alright
    Oh, the girl in my mirror
    Is cryin' ‘cause of you
    And I wish there was something
    Something I could do
    If I could I would tell her
    Not to be afraid
    The pain that she’s feeling
    Of sense of loneliness will fade
    So dry your tears and rest assured
    Love’ll find your heart deeper
    When she's looking back at me
    I know nothin’ really works that easily
    I can't believe it's what I see
    And that the girl in the mirror
    The girl in the mirror is me...'''
    
    s='''.,"?!;:'''
    for i in s:
        song=song.replace(i,'')
    wordlist=song.lower().split()
    
    
    wordDict={}
    wordSet=set(wordlist)
    for w in wordSet:
        wordDict[w]=wordlist.count(w)
    for i in wordDict:
        print(i,wordDict[i])
    dictList=list(wordDict.items())
    prep={'a','but','in','not','if','will','the','and','so'}
    for i in prep:
        del(wordDict[i])
    wordDict1= sorted(wordDict.items(),key=lambda d:d[1],reverse= True)
    for i in range(10):
        print(wordDict1[i])

  • 相关阅读:
    SpringIOC的小例子
    java中递归实现复制多级文件夹
    快速排序和几种简单排序
    Oracle面试的基本题
    多态的两个小例子
    单例模式
    内部类与匿名内部类
    C#
    C#
    C#
  • 原文地址:https://www.cnblogs.com/qq974975766/p/8649610.html
Copyright © 2011-2022 走看看