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

    #coding=utf-8
    
    song='''
    Skies,where the blue birds fly,
    Clouds where the people place their souls on to.
    Brighter,the sunshines that go through my tears,
    like searching for what heals my sorrows,
    Cry,when the twilight's come,
    Rise,when the people's prayer's melt in to.
    one,to where we'd been together in the sphere.
    I'm searching for where you are,my soul,
    I don't know how to put my heart belongs to you;
    I don't know how to love someone expect for you;
    That is all my world to been had you in my life.
    I'll call you all the time,
    Skies,where the blue birds cry,
    Clouds where the people forgot their souls on to,
    Brighter,the sunshines that go through my tears,
    like searching for what heals my sorrows,
    I don't know what was right or wrong for all I've told you;
    I don't know what was true or false that you've said to me;
    But it's all my love to believe in you in my life.
    I'll call you all the time.
    '''
    ellipsis_word={',','.',';',':','?','!','-'}   #将一些符号替换成空格
    for i in ellipsis_word:
        song.replace(i,'')
    
    Capital_word=song.lower().split()   #大小写替换,并分解
    
    Words={}
    for i in set(Capital_word):     #设置集合
        Words[i]=Capital_word.count(i)
    
    delete_word={'a', 'too', 'in', 'of', 'will', 'the', 'and', 'are', 'with', 'to', 'said', 'as', 's'}
    for i in delete_word:        #删除出现的语法过渡词
        if i in Words:
            Words.pop(i)         #移除列表元素
    
    sort_word = sorted(Words.items(), key= lambda d:d[1], reverse = True)  # 排序
    for i in range(10):
        print(sort_word[i])

    截图:

  • 相关阅读:
    Hibernate检索策略与检索方式
    获取分组后的TOP 1和TOP N记录
    Oracle 高级排序函数 和 高级分组函数
    Java中的字符串常量池
    代码的完整性:打印1到最大的n位数
    代码的完整性:数值的整数次方
    递归和循环:矩形覆盖
    位运算:二进制中1的个数
    递归和循环:变态跳台阶
    递归和循环:跳台阶
  • 原文地址:https://www.cnblogs.com/tiankongyiluozhiwu/p/8649770.html
Copyright © 2011-2022 走看看