zoukankan      html  css  js  c++  java
  • 9/20

      1. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
        score=list('112233345611')
        print('分数为:')
        print(score)
        score.sort()
        print('排列后:')
        print(score)
        print('计数1:')
        print(score.count('1'))
        print('计数3:')
        print(score.count('3'))
        score.pop(5)
        print(score)
      2. 字典实例:建立学生学号成绩字典,做增删改查遍历操作。
        zd={"江雨斌":"90","张侦讯":"98","黄志涛":"77","梁浩燃":"88"}
        print(zd)
        zd['王文杰']='59'
        print(zd)

      3. 列表,元组,字典,集合的遍历。
        总结列表,元组,字典,集合的联系与区别。
        lb=list('1223334444455555666666')
        yz=tuple('1223334444455555666666')
        jh=set('1223334444455555666666')
        zd={"jyb":"b6014","zzx":"b5008","hzt":"b6016"}
        print('列表遍历:')
        print(lb)
        for i in lb:
            print(i,end=' ')
        print('
        ')
        print('元组遍历:')
        for i in yz:
            print(i,end=' ')
        print('
        ')
        print('集合遍历:')
        for i in jh:
            print(i,end=' ')
        print('
        ')
        print('字典遍历:')
        for i in zd:
            print(i,end=' ')

      4. 英文词频统计实例
        1. 待分析字符串
        2. 分解提取单词
          1. 大小写 txt.lower()
          2. 分隔符'.,:;?!-_’
        3. 计数字典
        4. 排序list.sort()
        5. 输出TOP(10)
          panama='''Daca nici asa nu-ti place
          Ia mai zboara-n Panama
          Zile zile zile zile eu alerg girl
          Mile mile mile mile pe maidan
          Pentru tine tine sa-ti dau un dar dar
          Cel mai de pret dar fara nici un ban ban
          Ganja iarba sunt inutile-tile
          Numai tu stii sa-mi dai aripile-pile
          In Jamaica sau in Chile Chile
          Inima face Boom-Boom numai pentru tine
          Eh eh eh eh eh eh eh eh eh eh
          Numai pentru tine
          Eh eh eh eh eh eh eh eh eh eh
          N-ai raspuns la telefon
          No problem te scot pe balcon
          Si-o sa vezi cu ochii tai
          Cum ti-aduc flori un camion
          Si iti cant asa cu chitara mea
          Daca nici asa nu-ti place
          Ia mai zboara-n Panama
          Ce pana mea
          Ah ah ah ah mai zboara-n Panama
          Ah ah ah ah zboara ce pana mea
          Ah ah ah ah mai zboara-n Panama
          Ah ah ah ah hai mai zboara
          Kile-kile kile-kile eu am dat jos
          Oricum baby nu erau de folos-los
          Mi-e dor de tine sunt intors pe dos-dos
          Acasa ajung la timp tre' sa o iau pe jos-jos
          La ce ne folosesc banii banii banii
          Daca tu imi dai iubire si zi de zi pun anii
          Ca Bonnie Clyde sa fiu doar eu cu tine
          Si o sa avem girl o iubire ca in filme
          Eh eh eh eh eh eh eh eh eh eh
          O iubire ca in filme
          Eh eh eh eh eh eh eh eh eh eh Eh
          N-ai raspuns la telefon
          No problem te scot pe balcon
          Si-o sa vezi cu ochii tai
          Cum ti-aduc flori un camion
          Si iti cant asa cu chitara mea
          Daca nici asa nu-ti place
          Ia mai zboara-n Panama Ce pana mea
          Ah ah ah ah mai zboara-n Panama
          Ah ah ah ah zboara ce pana mea
          Ah ah ah ah mai zboara-n Panama
          Ah ah ah ah Eh Oh no
          Baby girl hai vino incoa'
          Am dragoste la mine o dau la schimb cu a ta
          Baby girl dragostea mea
          E de calitate dau gramul gram hai ia
          N-ai raspuns la telefon
          No problem te scot pe balcon
          Si-o sa vezi cu ochii tai
          Cum ti-aduc flori un camion
          Si iti cant asa cu chitara mea
          Daca nici asa nu-ti place
          Ia mai zboara-n Panama Ce pana mea
          Ah ah ah ah mai zboara-n Panama
          Ah ah ah ah zboara ce pana mea
          Ah ah ah ah mai zboara-n Panama
          Ah ah ah ah hai ma zboara Pwaah'''
          panama=panama.replace('?',' ')
          panama=panama.replace('!',' ')
          panama=panama.replace(',',' ')
          panama=panama.replace('.',' ')
          panama=panama.replace('-',' ')
          panama=panama.replace('&',' ')
          panama=panama.lower()
          
          words=panama.split(' ')
          zd={}
          key=set(words)
          for i in key:
              zd[i]=words.count(i)
          lb=list(zd.items())
          lb.sort(key=lambda x:x[1],reverse=True)
          print('频率最高top10:
          ')
          for i in range(10):
              print(lb[i])

  • 相关阅读:
    [书目20071127]图书 时间陷阱 目录
    [文摘20071113]十四项心理定律
    Win2003下:JDK1.5 + Eclipse3.2 + Tomcat6.0 + tomcatPluginV32
    [转]初试eclipse mysql
    [转]测试工具
    [转]如何进行软件需求分析
    OA流程设计尝试:Div步骤拖动
    [转]需求分析的20条法则
    Eclipse 3.2 + Tomcat 5.5 + Lomboz 3.2 简单配置
    [转]软件项目管理中的风险管理研究
  • 原文地址:https://www.cnblogs.com/bb437601841/p/7560560.html
Copyright © 2011-2022 走看看