列表切片list slicing
来源:互联网 发布:数据恢复 破解版 编辑:程序博客网 时间:2024/05/12 00:37
List slicing allows us to access elements of a list in a concise manner. The syntax looks like this:
[start:end:stride]
Where start
describes where the slice starts (inclusive), end
is where it ends (exclusive), and stride
describes the space between items in the sliced list. For example, a stride of 2
would select every other item from the original list to place in the sliced list.
l = [i ** 2 for i in range(1, 11)]# Should be [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]print l[2:9:2]
结果
[9, 25, 49, 81]
第一个参数为起始位置(包含),第二个为结束位置(不包含),第三个为跨度(每几个取一个)
反转list
my_list = range(1, 11)backwards = my_list[::-1]print backwards
结果
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
跨度为负则会从最末往前取
0 0
- 列表切片list slicing
- 什么是对象切片(Object Slicing)?
- 什么是对象切片(Object Slicing)?
- Python-切片的理解(Slicing)
- 使用切片(Slicing)准备按钮模板
- P3017 [USACO11MAR]布朗尼切片Brownie Slicing
- list(0列表的函数『索引 切片 追加 删除 长度 切片 循环』
- 【Python笔记】剖析Python的切片(slicing)语法
- 【Python笔记】剖析Python的切片(slicing)语法
- Python学习笔记(八)—切片(slicing)
- python中numpy矩阵的切片操作slicing心得
- Unity_切片精灵表(Slicing Sprite Sheets)_074
- slicing
- python 列表切片
- Python列表切片详解([][:][::])
- python06-切片、列表生成器
- Python列表切片
- Python列表切片详解([][:][::])
- jquery.banner.js图片更换
- HDU 5272 Dylans loves numbers
- hdu 5273 Dylans loves sequence
- Java并发编程-31-阻塞式优先级列表-PriorityBlockingQueue
- -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a
- 列表切片list slicing
- BP算法与公式推导
- 学编程为什么这么难?每个新手绝对要知道的那些事
- Java collection class demo
- Redis数据类型之SORTEDSET类型
- hdu 水题
- [leetcode] Gas Station
- LINUX下配置JDK环境变量
- No such table xxx错误的原因、解决办法: