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

  • 相关阅读:
    linq TO sqlite
    sqliteHelp类似sqlHelp
    Coolite Toolkit 学习笔记(1)
    多线程和委托简单例子
    datatableToObject 方法
    Linq To lucen.Net
    读取TXT文档示例
    VS2008快捷方式
    富文本编辑器嵌入指定html代码
    代码行数的统计
  • 原文地址:https://www.cnblogs.com/qq974975766/p/8649610.html
Copyright © 2011-2022 走看看