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

  • 相关阅读:
    5.性能测试工具比较:Jmeter和LR
    4.性能测试工具
    10.性能测试软技能
    7.性能测试流程
    Jmeter中文乱码
    Jmeter启动闪退
    tortoiseGit did not exit cleanly (exit code 128)
    职场沟通技巧
    TortoiseGit连接gitlab,一直要求输入密码
    Webmin代码执行漏洞复现
  • 原文地址:https://www.cnblogs.com/123hyf/p/7596014.html
Copyright © 2011-2022 走看看