zoukankan      html  css  js  c++  java
  • 英语词频统计

    music="""
    Why don't I like the girl I see
    The one who's standing right in front of me
    Why don't I think before I speak
    I should have listened to that voice inside me
    I must be stupid, must be crazy, must be out of my mind
    To say the kind of things I said last night
    Mirror mirror hanging on the wall
    You don't have to tell me who's the biggest fool of all
    Mirror mirror I wish you could lie to me
    And bring my baby back, bring my baby back to me
    (Mirror mirror lie to me
    Show me what I wanna see
    Mirror mirror lie to me
    Show me what I wanna see)
    Why did I let you walk away
    When all I had to do was say I'm sorry
    I let my pride get in the way
    And in the heat of the moment I was to blame
    I must be stupid, must be crazy, must be out of my mind
    Now in the cold light of the day I realize
    Mirror mirror hanging on the wall
    You don't have to tell me who's the biggest fool of all
    Mirror mirror I wish you could lie to me
    And bring my baby back, bring my baby back to me
    If only wishes could be dreams
    And know my dreams could come true
    There would be two us standing here in front of you
    If you could show me that someone that I used to be
    Bring back my baby, my baby to me
    Mirror mirror hanging on the wall
    You don't have to tell me who's the biggest fool of all
    Mirror mirror I wish you could lie to me
    And bring my baby back, bring my baby back to me
    Mirror mirror hanging on the wall
    You don't have to tell me who's the biggest fool of all
    Mirror mirror I wish you could lie to me
    And bring my baby back, bring my baby back to me
    (Mirror mirror lie to me
    Show me what I wanna see
    Mirror mirror lie to me)
    To me...
    (Mirror mirror lie to me
    Show me what I wanna see
    Mirror mirror lie to me
    """

    symbol = list(''',.?!’:"“”-%$''')
    for i in symbol:
    music = music.replace(i, ' ')
    music = music.lower()
    split = music.split()
    word = {}
    for i in split:
    count = music.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 don't
    '''
    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])



    运行结果:

    
    
  • 相关阅读:
    (转)C# 泛型委托 Action<>和Func<>
    (转)ASP.NET Core 中间件与筛选器
    react中将svg做成icon组件在其他模块调用
    react简单的tab切换 (styled-components)
    计算购物车金额总和( jquery )
    js分享功能(微信,QQ,微博,空间,豆瓣等)
    AJAX入门介绍
    作为前端,你不得不知道的搜索引擎优化
    微信小程序实现图片双滑缩放大小
    swiper实现一个好看的轮播图
  • 原文地址:https://www.cnblogs.com/hhmk/p/8637938.html
Copyright © 2011-2022 走看看