zoukankan      html  css  js  c++  java
  • 七、英文词频统计预备,组合数据类型练习

    1. 实例: 下载一首英文的歌词或文章,将所有,.?!等替换为空格,将所有大写转换为小写,统计某几个单词出现的次数,分隔出一个一个的单词。
      w ='''We don't talk anymore 
      We don't talk anymore 
      We don't talk anymore 
      Like we used to do 
      We don't laugh anymore 
      What was all of it for ? 
      We don't talk anymore 
      Like we used to do 
      I just heard you found the one you'vebeen lookin' 
      You been looking for 
      I wish i would've konwn that wasn't me 
      Cause even after all this time i still wonder 
      Why i can't move on ? 
      Just the way you dance so easliy 
      Don't wanna know 
      The kinda dress you're wearin' tonight 
      If he's holdin' onto you so tight 
      The way i did before 
      I overdosed 
      Should've known your love was game 
      Now I can't get'cha outof my brain 
      Ooh it's such a shame 
      We don't talk anymore 
      We don't talk anymore 
      We don't talk anymore 
      Like we used to do 
      We don't laugh anymore 
      What was all of it for ? 
      We don't talk anymore 
      Like we used to do 
      Selena : I just hope you'r lyin' next to somebody 
      Know it's hard to love yalike me 
      Must be a good reason that you're gone 
      Every now and then 
      I think you might want me to come show up yourdoor 
      But I'm just too afraidthat i'll be worng 
      Don't wanna know 
      If you'ra lookin' intoher eyes 
      If she's holdin' onto youso tight 
      The way i did before 
      I overdosed 
      Should've know your lovewas a game 
      Now I can't get'cha outof my brain 
      Ooh it's such a shame 
      '''
      w = w.lower()
      w = w.replace('?',' ')
      words=w.split(' ')
      print(words)
      print("talk出现的次数为:"+str(w.count('talk')))

    2. 列表实例:由字符串创建一个作业评分列表,做增删改查询统计遍历操作。例如,查询第一个3分的下标,统计1分的同学有多少个,3分的同学有多少个等。
      grade=list('2333123456')
      print('评分列表:',grade)
      for i in range(len(grade)):
          grade[i]=int(grade[i])
      print('作业成绩',grade)
      
      grade.append(7)
      print('增加一个学生成绩:',grade)
      
      grade.pop(1)
      print('删除下标为1的同学的成绩:',grade)
      
      grade[4]=3
      print('把下标为4的同学的成绩修改成3:',grade)
      
      grade.index(3)
      print('第一个3分的下标:',grade)
      
      print("得1分的同学有:"+str(grade.count(1))+"")
      print("得3分的同学有:"+str(grade.count(3))+"")

      运行结果:
      = RESTART: C:/Users/dell/AppData/Local/Programs/Python/Python36/python作业7.py =
      评分列表: ['2', '3', '3', '3', '1', '2', '3', '4', '5', '6']
      作业成绩 [2, 3, 3, 3, 1, 2, 3, 4, 5, 6]
      增加一个学生成绩: [2, 3, 3, 3, 1, 2, 3, 4, 5, 6, 7]
      删除下标为1的同学的成绩: [2, 3, 3, 1, 2, 3, 4, 5, 6, 7]
      把下标为4的同学的成绩修改成3: [2, 3, 3, 1, 3, 3, 4, 5, 6, 7]
      第一个3分的下标: [2, 3, 3, 1, 3, 3, 4, 5, 6, 7]
      得1分的同学有:1个
      得3分的同学有:4个
      >>>

             3.简要描述列表与元组的异同。

    答:

     同:列表和元组十分类似,列表和项目都可以添加删除或是搜索列表中的项目。

     异:列表中的项目应该包括在方括号中,元组的项目应该包括在圆括号中;列表是可变的数据类型,即这种类型是可以被改变的,但元组是不可变的,也就是说你不能修改元组。

  • 相关阅读:
    如何通过css控制内容显示顺序 第二行的内容优先显示
    《掌上流年》“国内首部微信日记”出版
    Hello Kitty微信主题很可爱?小心财产安全!
    第三方网站不能调用微信公众平台里的图片了 显示"此图片来自微信公众号平台未经允许不可引用"
    鼓浪屿船票也能用微信支付了
    excel判断单元格包含指定内容的函数用=IF(COUNTIF(A1,"*内容*"),"0","1")
    认证的政府与媒体类订阅号可取得网页授权接口了
    来八卦一下常刷微信朋友圈的你属于什么类型
    微信稳居Android App排行榜4月份国内榜首
    [福利]非认证公众帐号也能申请微信连Wi-Fi了
  • 原文地址:https://www.cnblogs.com/Green-/p/7574103.html
Copyright © 2011-2022 走看看