zoukankan      html  css  js  c++  java
  • 作业

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

    d={'01': 85, '02': 96, '03': 78, '04': 91, '05': 87}
    print(d,'
    ')
    #增加#
    d['06']=66
    print('增加后的成绩为:',d,'
    ')
    #删除#
    d.pop('04')
    print('删除后的成绩为:',d,'
    ')
    #修改#
    d['05']=80
    print('修改后的成绩为:',d,'
    ')
    #查找#
    print('02同学的成绩为:',d['02'],'
    ')           
    
    for i in d:
        print('学号{}分数为{}'. format(i,d[i]))

    #补充笔记:建立一个学号成绩字典

    dic={}
    number=['01','02','03','04','05']
    scores=[85,96,78,91,87]
    ns=dict(zip(number,scores))
    print(ns)
    #学号#
    d.keys()
    print(d.keys())
    print(d.values())
    #获取不存在的07学号值#
    print(d.get('07','null'))
    #查01的成绩#
    print(d.get('01'))
    print(d.items())

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

         列表是一个串行的数据结构,就是一组的字符的列表。比如定义一个列表。定义一个“cities”,然后我用中括号括起来,里面是字符串,然后输入代码“len(cities)”查看cities的长度,然后可以看到有三个。列表可以根据下标来查找值。
         元组是支持各种类型在一起的,比如说要描述一个人。 定义一个人,输入tom,它有“mouse,finger,年龄18,性别女”,加上个type,type可以当做一个整体传参到函数里面,或者在返回多个值的时候,把它赋予一个type。
         字典就是配对关系,就是减值对的组合。
    输入代码,“love={‘name’:’sundy’,’age’:18}”,然后点击回车,这就是字典,假如我们要打印出其中的年龄,也是非常的简单,就直接输入代码,用它的“age”就有相应的18出现。

         集合最后显示的是不重复的内容,具有排异性,无序的,不能用下标查找,其他跟列表差不多。

    3、英文词频统计实例

    待分析字符串分解提取单词

    1. 大小写 txt.lower()
    2. 分隔符'.,:;?!-_’
    3. 单词列表     

           4.单词计数字典

    news='''Just one last dance,
    The wine and the lights and the Spanish guitar
    I'll never forget how romantic they are
    But I know' tomorrow I'll lose the one I love
    There's no way to come with you.
    It's the only thing to do
    Just one last dance?
    Before we say goodbye
    When we sway and turn round and round and round
    It's like the first time
    Just one more chance
    Hold me tight and keep me warm
    Cause the night is getting cold
    And I don't know where I belong
    Just one last dance,
    Oh'Baby
    Just one last dance,
    Before we say goodbye,
    When we sway and turn round and round and round,
    It's like the first time
    Just one more chance,
    Hold me tight and keep me warm'''
    #大小写转换#
    news=news.lower()
    #去标点#
    for i in ',.?':
        news=news.replace(i,' ')
        print(news)
    #转为列表#   
    words=news.split(' ')
    print(words)

  • 相关阅读:
    为Fiddler增加Burp-like Inspector扩展 实现类似Burpsuite爆破、一键重放、编码转换等功能
    SVN常见问题总结一
    手把手教你学SVN
    js基本语法汇总
    最全的常用正则表达式大全
    CSS padding margin border属性详解
    从零开始学习jQuery (五) 事件与事件对象
    js正则表达式语法
    浏览器内部工作原理
    原生AJAX入门讲解(含实例)
  • 原文地址:https://www.cnblogs.com/1244581939cls/p/7596005.html
Copyright © 2011-2022 走看看