• 1、列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。

    >>>score=list('21223113321')
    >>>print('作业评分列表:',score)
    >>>score.append('3')
    >>>print('增加:',score)
    >>>score.pop()
    >>>print('删除:',score)
    >>>score.insert(2,'1')
    >>>print('插入:',score)
    >>>score[2]='2'
    >>>print('修改:',score)
    >>>print('第一个3分的下标:',score.index('3'))
    >>>print('1分的个数:',score.count('1'))
    >>>print('3分的个数:',score.count('3'))

  • 2、字典实例:建立学生学号成绩字典,做增删改查遍历操作。
    >>>d={'洪英杰':93,'郭子维':74,'王五':45,'徐均钧':66}
    >>>print('学生成绩字典:',d)
    >>>d['钱二']=92
    >>>print('增加:',d)
    >>>d.pop('徐均钧')
    >>>print('删除:',d)
    >>>d['张三']=73
    >>>print('修改:',d)
    >>>print('查询李四成绩:',d.get('李四','无'))

  • 3、列表,元组,字典,集合的遍历。
    >>>ls=list("4613125646")
    >>>tu=tuple("4613125646")
    >>>s=set("4613125646")
    >>>d={'洪英杰':93,'郭子维':74,'王五':45,'徐均钧':66}
    >>>print("列表:",ls)
    >>>for i in ls:print(i,end=' ')
    >>>print("\n")
    >>>print("元组:",tu)
    >>>for i in tu:print(i,end=' ')
    >>>print("\n")
    >>>print("集合:",s)
    >>>for i in s:print(i,end=' ')
    >>>print("\n")
    >>>print("字典:",d)
    >>>for i in d:print(i,end='\t')
    >>>print(d[i],end='\n')


  • 4、英文词频统计实例
    1. 待分析字符串
    2. 分解提取单词
      1. 大小写 txt.lower()
      2. 分隔符'.,:;?!-_’
    3. 计数字典
    4. 排序list.sort()
    5. 输出TOP(10)
    • faded = '''You were the shadow to my light
      Did you feel us?
      Another start
      You fade away
      Afraid our aim is out of sight
      Wanna see us
      Alive
      Where are you now?
      Where are you now?
      Where are you now?
      Was it all in my fantasy?
      Where are you now?
      Were you only imaginary?
      Where are you now?
      Atlantis
      Under the sea
      Under the sea
      Where are you now?
      Another dream
      The monster's running wild inside of me
      I'm faded
      I'm faded
      So lost, I'm faded
      I'm faded
      So lost, I'm faded
      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?
      Under the bright but faded lights
      You've set my heart on fire
      Where are you now?
      Where are you now?
      Where are you now?
      Atlantis
      Under the sea
      Under the sea
      Where are you now?
      Another dream
      The monster's running wild inside of me
      I'm faded
      I'm faded
      So lost, I'm faded
      I'm faded
      So lost, I'm faded'''faded = faded.lower()
      for i in '?!,.\'\n':faded = faded.replace(i,' ')
      words = faded.split(' ')dic={}
      keys = set(words)
      for i in keys:dic[i]=words.count(i)c = list(dic.items())
      c.sort(key=lambda x:x[1],reverse=True)for i in range(10):print(c[i])

    • 建立学生学号成绩字典

      >>>score = {10:'41',20:'64',30:'71',40:'81',50:'91'}
      >>>print(score)
      >>>score[6] = '90'
      >>>print(score)
      >>>score.pop(6)
      >>>print(score)>>>for i in score:print("{:>2} : {:<2}".format(i,score.get(i)))

      列表,元组,字典,集合

      >>>ls=list("4613125646")
      >>>tu=tuple("4613125646")
      >>>se=set("4613125646")
      >>>d={'阿一':93,'阿二':74,'阿三':45,'阿四':66}
      >>>print("列表:",ls)
      >>>for i in ls:print(i,end=' ')
      >>>print("\n")
      >>>print("元组:",tu)
      >>>for i in tu:print(i,end=' ')
      >>>print("\n")
      >>>print("集合:",se)
      >>>for i in se:print(i,end=' ')
      >>>print("\n")
      >>>print("字典:",d)
      >>>for i in d:print(i,end='\t')print(d[i],end='\n')

      歌词统计

      >>>song = '''Vincent,Don McLean. Starry starry nightpaint your palette blue and greylook out on a summer\'s daywith eyes that know the darkness in my soul.Shadows on the hillssketch the trees and the daffodilscatch the breeze and the winter chillsin colors on the snowy linen land.And now I understandwhat you tried to say to meand how you suffered for your sanityand how you tried to set them free.They would not listen they did not know howperhaps they\'ll listen now.Starry starry nightflaming flowers that brightly blazeswirling clouds in violet hazereflect in Vincent\'s eyes of China blue.Colors changing huemorning fields of amber grainweathered faces lined in painare smoothed beneath the artist\'s loving hand.And now I understandwhat you tried to say to meand how you suffered for your sanityand how you tried to set them free.They would not listen they did not know howperhaps they\'ll listen now.For they could not love youbut still your love was trueand when no hope was left in sight on thatstarry starry night.You took your life as lovers often do,But I could have told you Vincentthis world was never meant for one as beautiful as you.Starry starry nightportraits hung in empty hallsframeless heads on nameless wallswith eyes that watch the world and can\'t forget.Like the stranger that you\'ve metthe ragged men in ragged clothesthe silver thorn of bloddy roselie crushed and broken on the virgin snow.And now I think I knowwhat you tried to say to meand how you suffered for your sanityand how you tried to set them free.They would not listen they\'re not listening stillperhaps they never will.'''>>>song = song.lower()
      >>>for i in '?!,.\'\n':
      >>> song = song.replace(i,' ')
      >>>words = song.split(' ')>>>dic={}
      >>>keys = set(words)
      >>>for i in keys:
      >>>dic[i]=words.count(i)>>>c = list(dic.items())
      >>>c.sort(key=lambda x:x[1],reverse=True)>>>for i in range(10):>>>print(c[i])

转载于:https://www.cnblogs.com/yingja-hong/p/7567595.html

组合数据类型练习,英文词频统计实例9-21相关推荐

  1. 组合数据类型,英文词频统计

    练习: 1.总结列表,元组,字典,集合的联系与区别. 列表 [,] 有序,可变,值可以重复 元组(,) 有序,不可修改,不可重复 集合可以用set()函数或者{}创建 用,分隔,不可有重复元素,是无序 ...

  2. 【作业】组合数据类型练习,英文词频统计实例

    1.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作.例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等. 1 score = list('012332211') ...

  3. 组合数据类型练习,英文词频统计实例上(2017.9.22)

    字典实例:建立学生学号成绩字典,做增删改查遍历操作. sno=['33号','34号','35号','36号'] grade=[100,90,80,120] d={'33号':100,'34号':90 ...

  4. 组合数据类型练习,英文词频统计实例上

    1.name=['陈楠芸','陈文琪','刘书签','杨必须'] scores=[7,6,6,5] d={'陈楠芸':7,'陈文琪':6,'刘书签':6,'杨必须':5} print(d) #增加 d ...

  5. 组合数据类型练习,英文词频统计实例

    1.列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作.例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等 score=list('21223113321') pr ...

  6. 复合数据类型,英文词频统计

    这次作业来源:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2753 1.列表,元组,字典,集合分别如何增删改查及遍历. (1)列表 ...

  7. 文件方式实现完整的英文词频统计实例

    可以下载一长篇的英文小说,进行词频的分析. 1.读入待分析的字符串 2.分解提取单词 3.计数字典 4.排除语法型词汇 5.排序 6.输出TOP(20) 7.对输出结果的简要说明. fo=open(' ...

  8. 文件方式实现完整的英文词频统计实例(9.27)

    1.读入待分析的字符串 2.分解提取单词 3.计数字典 4.排除语法型词汇 5.排序 6.输出TOP(20) 文本代码如下: girl='''Remembering me, Discover and ...

  9. 064文件方式实现完整的英文词频统计实例

    fr = open('test.txt' , 'r',encoding='utf-8')s = fr.read() s=s.lower()s=s.replace('\n',' ')word=s.spl ...

最新文章

  1. python 创建只读的函数(@property的介绍与使用)
  2. vi使用技巧(转载)
  3. linux 公私钥生成,[c++,openssl,RSA] linux下编程实现生成公私钥对_1
  4. scrapy-redis组件写分布式爬虫实战
  5. js粘贴板为什么获取不到图片信息_JavaScript 学习笔记(3):图片库
  6. Delphi XE7 Update1修正列表
  7. 以非泛型方式调用泛型方法(三)
  8. 项目管理基础:系统分析相关概念介绍
  9. Spring Boot flyway的启动时机比较早
  10. 23-新建maven 项目
  11. iOS开发项目篇—02添加子控制器以及项目分层
  12. 计算机相关国内外文献,计算机外文文献
  13. xmarks恢复使用
  14. Composer Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
  15. (附源码)app学科竞赛活动报名系统 毕业设计 012239
  16. 用异地组网路由器,实现家校互联
  17. ILOG JRules 规则管理系统保险行业应用
  18. 讨厌的HR [转贴] --一篇颇有争议的文章
  19. conda离线安装包
  20. JavaOOP 面试题

热门文章

  1. element走马灯自动_Element Carousel 走马灯的具体实现
  2. qpython3使用手册图_qpython图形
  3. java cpu 监控工具_Java自带的GUI性能监控工具Jconsole以及JisualVM简介
  4. Oracle 分页查询语句SQL
  5. feignRequest$Options错误
  6. 文本编辑器_国外程序员最爱的5种文本编辑器
  7. python爬取b站用户_用Python爬取bilibili全站用户信息
  8. comparator比较器用法_Python学习:好像很少人知道 Python iter() 的另外一个用法?...
  9. Mysql Too many connections解决方法
  10. python函数和方法概念_第48p,什么是函数?,Python中函数的定义