当前位置: 首页 > news >正文

菜鸟教程《Python 3 教程》笔记(15):数据结构

菜鸟教程《Python 3 教程》笔记(15)

  • 15 数据结构
    • 15.1 将列表当作队列使用
    • 15.2 遍历技巧

笔记带有个人侧重点,不追求面面俱到。

15 数据结构

出处: 菜鸟教程 - Python3 数据结构

15.1 将列表当作队列使用

在列表的最后添加或者弹出元素速度快,然而在列表里插入或者从头部弹出速度却不快(因为所有其他的元素都得一个一个地移动)。

15.2 遍历技巧

遍历字典:

>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.items():
...     print(k, v)
...
gallahad the pure
robin the brave

遍历列表:

>>> for i, v in enumerate(['tic', 'tac', 'toe']):
...     print(i, v)
...
0 tic
1 tac
2 toe

遍历多个序列:

>>> questions = ['name', 'quest', 'favorite color']
>>> answers = ['lancelot', 'the holy grail', 'blue']
>>> for q, a in zip(questions, answers):
...     print('What is your {0}?  It is {1}.'.format(q, a))
...
What is your name?  It is lancelot.
What is your quest?  It is the holy grail.
What is your favorite color?  It is blue.

反向遍历:

>>> for i in reversed(range(1, 10, 2)):
...     print(i)
...
9
7
5
3
1
http://www.lryc.cn/news/151768.html

相关文章:

  • CH05_介绍重构名录
  • 1、Nginx 简介
  • C++之——宏
  • 代码随想录打卡—day56—【编辑距离】— 9.2 编辑距离系列
  • uni-app app端.m3u8类型流的播放
  • 使用proxy_pool来为爬虫程序自动更换代理IP | 开源IP代理
  • 【易售小程序项目】修改“我的”界面前端实现;查看、重新编辑、下架自己发布的商品【后端基于若依管理系统开发】
  • Centos7 + Apache Ranger 2.4.0 部署
  • 硬件SPI口扩展
  • 【jsthree.js】全景vr看房进阶版
  • 实战:基于卷积的MNIST手写体分类
  • Ubuntu开启生成Core Dump的方法
  • git视频教程Jenkins持续集成视频教程Git Gitlab Sonar教程
  • 机器学习:Xgboost
  • 《Kubernetes部署篇:Ubuntu20.04基于二进制安装安装cri-containerd-cni》
  • [CISCN 2019初赛]Love Math
  • 运行命令出现错误 /bin/bash^M: bad interpreter: No such file or directory
  • 码农重装系统后需要安装的软件
  • Kotlin return 和 loop jump
  • 计算一组数据中的低中位数即如果一组数据中有两个中位数则较小的那个为低中位数statistics.median_low()
  • ChatGPT是否能够协助人们提高公共服务和社区建设能力?
  • 机器人中的数值优化(七)——修正阻尼牛顿法
  • 程序员自由创业周记#3:No1.作品
  • 固定资产制度怎么完善管理?
  • 神经网络--感知机
  • Java“牵手”1688图片识别商品接口数据,图片地址识别商品接口,图片识别相似商品接口,1688API申请指南
  • 科技资讯|微软获得AI双肩包专利,Find My防丢背包大火
  • 数学建模:多目标优化算法
  • arcmap 在oracle删除表重新创建提示表名存在解决放啊
  • 新版HBuilderX在uni_modules创建搜索search组件