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

    cc = ('''Counting stars Lately I've been, I've been losing sleep   
    Dreaming 'bout the things that we could be   
    But baby I've been, I've been prayin' hard     
    Said no more counting dollars   We'll be counting stars   
    Yeah, we'll be counting stars   I see this life Like a swinging vine  
     Swing my heart across the line   In my face is flashing signs   Seek it out and ye shall find
      Old, but I'm not that old   Young, but I'm not that bold   And I don't think the world is sold  
     I'm just doing what we're told   I, feel something so right   But doing the wrong thing   
    I, feel something so wrong   But doing the right thing   I could lie, could lie, could lie  
     everything that kills me makes me feel alive   Lately I've been, I've been losing sleep  
     Dreaming 'bout the things that we could be   Baby I've been, I've been prayin' hard  
     Said no more counting dollars   We'll be counting stars   Lately I've been, I've been losing sleep   
    Dreaming 'bout the things that we could be   Baby I've been, I've been prayin' hard   Said no more counting dollars  
     We'll be, we'll be counting stars   I feel the love And I feel it burn   Down this river every turn  
     Hope is a four letter word   Make that money   Watch it burn   Old, but I'm not that old  
     Young, but I'm not that bold   And I don't think the world is sold   I'm just doing what we're told  
     I, feel something so wrong   But doing the right thing   I could lie, could lie, could lie  
     Everything that drowns me makes me wanna fly   Lately I've been, I've been losing sleep  
     Dreaming 'bout the things that we could be   Baby I've been, I've been prayin' hard
      Said no more counting dollars   We'll be counting stars   Lately I've been, I've been losing sleep  
     Dreaming 'bout the things that we could be   Baby I've been, I've been prayin' hard  
     Said no more counting dollars   We'll be, we'll be counting stars   Take that money And watch it burn   Sink in the river
    ''')
    cc = cc.replace('.', ' ')
    ccList = cc.split()
    print(len(cc), ccList)  # 分隔一个单词并统计英文单词个数
    ccSet = set(ccList)  # 将列表转化成集合,再将集合转化成字典来统计每个单词出现个数
    
    print(ccSet)
    
    
    strDict = {}
    # for star in ccSet:
    #     strDict[star] = ccList.count(star)
    # print(strDict, len(strDict))
    for star in ccSet:
        strDict[star]=cc.count(star)
    for key in ccSet:
        print(key,strDict[key])
    wclist=list(ccSet.items())
    print(wclist)
    def takeSecond(elem):
        return  elem[1]
    wclist.sort(key=takeSecond,reverse=True)
    print(wclist)
    

      

     
    #列表的遍历
    
    cclist = ['wqdq','dqd','Awd',313,'小四','dqd']
    print(cclist)
    cclist.append('gegeheh')
    print(cclist)
    cclist.pop(2)
    print(cclist)
    for i in cclist:
        print(i)
    
    
    #元组的遍历
    
    tuple = ('jtfjhrr','rqfw f2q',800,10)
    print(tuple[2])
    for i in tuple:
        print(i)
    
    
    #字典的遍历
    
    dic = {'fhehe': '4w6436', 'jgdns': 7, '4w6436': 'First'}
    
    print('fhehe:' , dic['fhehe'])
    print('4w6436:', dic['4w6436'])
    
    dic['4w6436'] = 8;
    dic['4w6436'] = "对接欧文机房的维护"
    
    print('4w6436:', dic['4w6436'])
    print('4w6436:', dic['4w6436'])
    
    for key in dic:
        print(key,':',dic.get(key))
    
    
    #集合的遍历
    
    a = set([1,2,3,6,5])
    print(a)
    
    a.add(4)
    print(a)
    a.add('uteru')
    print(a)
    
    a.remove(5)
    print(a)
    
    for i in a:
        print(i)
    

      

  • 相关阅读:
    SVN和IntelliJ IDEA忽略node_module设置
    通过出版一本案例方面的图书来包装自己(实施篇)
    在著名出版社出版书,你也行——记录我写书出版的经历和体会
    从事务角度粗窥架构的可扩展性和可维护性:内容整理自java web轻量级开发面试教程
    Hibernate(或其它ORM)里的inverse用法详解,内容摘自Java web轻量级开发面试教程
    Java web轻量级开发面试教程的前言
    根据实践经验,讲述些学习Java web能少走的弯路,内容摘自java web轻量级开发面试教程
    面试时,当你有权提问时,别客气,这是个逆转的好机会(内容摘自Java Web轻量级开发面试教程)
    通过Struts了解MVC框架,兼说如何在面试中利用Struts证明自己
    从一个简单案例上手Spring MVC,同时分析Spring MVC面试问题
  • 原文地址:https://www.cnblogs.com/cc013/p/9752633.html
Copyright © 2011-2022 走看看