zoukankan      html  css  js  c++  java
  • 组合数据类型练习,英文词频统计实例上

    1、字典实例:建立学生学号成绩字典,做增删改查遍历操作。

    #建立学生学号成绩字典
    d={'01':'80','02':'90','03':'89','04':'90','05':'100'}
    print(d)
    
    #增遍历操作
    d['06']='100'
    
    #删遍历操作
    d.pop('01')
    
    #改遍历操作
    d['04']='100'
    
    #查遍历操作
    print(d['04'])
    
    for i in d:
        print(d)

    2、列表,元组,字典,集合的遍历。

    总结列表,元组,字典,集合的联系与区别。

    G=list('123345237646')
    for i in G:
        print(G)
        
    S=tuple('abcdefghi')
    for i in S:
        print(S)
    
    d={'01':'70','02':'90','03':'100','05':'79'}
    for i in d:
        print(d)
    
    se=set('12435433224')
    for i in se:
        print(se)

     

    3、英文词频统计实例

    s='''You were the shadow to my light
    
    Did you feel us?
    
    Another star
    
    You fade away
    
    Afraid our aim is out of sight
    
    
    Were you only imaginary?
    
    Where are you now?
    
    Atlantis
    
    Where are you now?
    
    Another dream
    
    These shallow waters never met what I needed
    
    I'm letting go a deeper dive
    
    Eternal silence of the sea. I'm breathing alive
    
    Where are you now?
    
    Where are you now?
    
    '''
    s=s.lower()
    print("全部大写转换为小写:"+s)
    
    for i in ',!?':
        s=s.replace(i,' ') 
        print('替换结果:'+s)
        
    s=s.split(' ')
    print('分隔结果为:',s)
    
    word = set(s)
    dic={}
    for i in word:
        dic[i]= s.count(i)
        
    s=list(dic.items())
    s.sort(key=lambda x:x[1],reverse=True)
    print(s,'
    ')
    print('TOP10:')
    for i in range(10):
        word,count=s[i]
        print('{}	{}'.format(word,count))

  • 相关阅读:
    生成函数学习笔记
    CF1437F Emotional Fishermen
    BZOJ 1443 [JSOI2009]游戏Game
    BZOJ 1018 [SHOI2008]堵塞的交通traffic
    访问量破1000之记录
    BZOJ 1022 [SHOI2008]小约翰的游戏John
    BZOJ1457 棋盘游戏
    BZOJ1874: [BeiJing2009 WinterCamp]取石子游戏
    BZOJ 1188 [HNOI2007]分裂游戏
    Codeforces Round #345 (Div. 2)
  • 原文地址:https://www.cnblogs.com/123hyf/p/7596014.html
Copyright © 2011-2022 走看看