万门大学数据结构与算法进阶(2)ArrayList 动态数组
Array
- ArrayList 动态数组/数组列表
- 基础知识
- 抽象数据类型
- Python Array vs. List
- Array Module - Sequence of fixed-type data
- python string
- List 实例
- List
ArrayList 动态数组/数组列表
基础知识
- 顺序储存数据
- 连续储存
- 任意顺序访问,可变大小的列表数据结构允许增加、删除元素
抽象数据类型
- E.g., a list of available hotel rooms, a list of cities, and a list of books
- Data Abstraction
- Decide what data elements you will be operating on
- Decide what operations you will be doing to each data element
- Define a clean interface to these operations
- Implement the objects
- Now you have an Abstract Data Type (ADT)
Python Array vs. List
数组和动态数组的最大区别:
数组的大小是固定的,动态数组的大小是可以改变的!
Array Module - Sequence of fixed-type data
- python array
用来储存序列的数据,且其中的数据必须有相同的数据类型:要求是全部为数字或者其它固定大小的原始类型如字节。(除了需要相同的数据类型之外,与 list 几乎一样)
import array
import binasciis = 'sample'
a = array.array('u', s)print('As string:', s)
print('As array :', a)As string: sample
As array : array('u', 'sample')
python string
- string
python 利用 string 来储存具有不同大小/长度的序列数据。
虽然初始元素的大小可能不同,但是用于存储每个元素的存储器地址的位的数目是固定的(每个地址例如,64位)
List 实例
切片操作
A single list instance may include multiple references to the same object as elements of the list, and it is possible for a single object to be an element of two or more lists, as those lists simply store references back to that object. As an example, when you compute a slice of a list, the result is a new list instance, but that new list has references to the same elements that are in the original list.
浅拷贝
# let's play some tricks
# array slicing: make a copy!!!a = list(range(0, 9))
print(a)
b = a[3:7]
print(b)b[0] = -1
print(a)
print(b)[0, 1, 2, 3, 4, 5, 6, 7, 8]
[3, 4, 5, 6]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
[-1, 4, 5, 6]
import numpy as npa = np.arange(10)
print(a)
b = a[3:7]
print(b)b[0] = -1
print(a)
print(b)b = a[3:7].copy()
print(b)
b[1] = -2
print(a)
print(b)[0 1 2 3 4 5 6 7 8 9]
[3 4 5 6]
[ 0 1 2 -1 4 5 6 7 8 9]
[-1 4 5 6]
[-1 4 5 6]
[ 0 1 2 -1 4 5 6 7 8 9]
[-1 -2 5 6]
- 深拷贝
a = [0] * 8
a[2] = 1
a[0, 0, 1, 0, 0, 0, 0, 0]
a = [[0] * 8] * 8
a[0][0] = 9
a[[9, 0, 0, 0, 0, 0, 0, 0],[9, 0, 0, 0, 0, 0, 0, 0],[9, 0, 0, 0, 0, 0, 0, 0],[9, 0, 0, 0, 0, 0, 0, 0],[9, 0, 0, 0, 0, 0, 0, 0],[9, 0, 0, 0, 0, 0, 0, 0],[9, 0, 0, 0, 0, 0, 0, 0],[9, 0, 0, 0, 0, 0, 0, 0]]
- 初始化二维的列表
To properly initialize a two-dimensional list, we must ensure that each cell of the primary list refers to an independent instance of a secondary list. This can be accomplished through the use of Python’s list comprehension syntax.
m, n = 3, 2
data = [ [0] * n for j in range(m) ]
data[[0, 0], [0, 0], [0, 0]]
List
字符串是字符的序列,列表是对象的序列。当对象的顺序很重要时,我们使用 LIst。
- ADT List Operations
- Create an empty list
- Determine whether the list is empty
- Determine the number of items in a list
- Add an item at given position in a list
- Remove the item at a given position in a list
- Remove all the items from a list
- Get the item at a given position in a list
- Other operations?
万门大学数据结构与算法进阶(2)ArrayList 动态数组相关推荐
- 万门大学倒闭了,童哲连夜跑路了
博雯 鱼羊 发自 凹非寺 量子位 | 公众号 QbitAI 万门大学,连夜跑路? 不仅是VIP群于凌晨解散,学员们一觉醒来发现自己被踢出了群. 甚至连内部员工也突然之间无法登录公司App. 根据网友爆 ...
- axure 小程序 网盘_万门大学微信小程序实战开发特训班【完结】网盘高清全套最新系列精品课程...
万门大学微信小程序实战开发特训班[完结]网盘高清全套最新系列精品课程 课 程 简介 我买了这个课程,课程很有价值,我们通过链接或百度网盘群的形式在共享资料库中与您共享,需要万门大学微信小程序实战开发特 ...
- 互联网晚报 | 3月22日 星期二 | 工作人员标注mu5735残骸并展开调查;万门大学疑似解散VIP群跑路...
工作人员标注mu5735残骸并展开调查 目前,东航客机mu5735的搜救工作正在进行.进入mu5735核心救援现场看到,多处树木存在燃烧痕迹,飞机残骸散落各处.工作人员正对飞机残骸进行标注,并对 ...
- 旧金山大学数据结构和算法的可视化工具
旧金山大学数据结构和算法的可视化工具,动态展示数据存储和查询: http://www.cs.usfca.edu/~galles/visualization/Algorithms.html
- 关于万门大学的《理论物理一个月特训》课程
首先,这是一篇转贴,为什么要转这个文章,是因为这个文章看完之后感触很深,看了校长在B站的复数部分,自然引入CR方程和傅里叶变换,有了醍醐灌顶的感觉,因为自己这两年在看大学的数学系类课程和物理系类课程时 ...
- 一周看点 | 腾讯回应“人员优化”;Go成大厂热门编程语言;京东开启裁员;万门大学疑似跑路...
▲ 点击上方"分布式实验室"关注公众号 回复"1"抽取纸质技术书 腾讯回应"人员优化"消息 3月23日,腾讯总裁刘炽平表示,"目前 ...
- 万门大学的软件测试特训班有用吗,为什么我要推荐《万门大学理论物理特训班》?来自一位学员的真实体验...
原标题:为什么我要推荐<万门大学理论物理特训班>?来自一位学员的真实体验 [如果想了解这是一门怎样的课程,那和我一探究竟吧] 有没有这样一门课?可以用一个月30天240小时(30*8)把本 ...
- 万门大学的软件测试特训班有用吗,app推荐|10款有趣的app分享(包含社交、学习等等),进来看看?...
现在的人呐,手机里不多装点app,都不好意思说自己是低头族. 今天我给大家分享几款我觉得有趣的app,比较小众,但对我来说都很喜欢. 但甲之蜜糖,乙之砒霜,如果你有觉得更好用的,可以推荐给我. 一.社 ...
- mooc数据结构与算法python版期末测验_中国大学数据结构与算法Python版答案_MOOC慕课章节期末答案...
中国大学数据结构与算法Python版答案_MOOC慕课章节期末答案 更多相关问题 java.lang 包的 Character 类的 isJavaIdentifierStart 方法的功能是用来判断某 ...
最新文章
- 体积小巧、功能强大的代理工具 -- 3proxy
- python的热潮_Python这么热,要不要追赶Python学习热潮?
- 计算机组装维护的概念,实用计算机组装与维护库及概念.doc
- 非常精确的测试运行时间(比clock()更精确些)
- Android之如何成为Android高手
- JQuery.lazyload 图片延迟加载
- 资源放送丨《Oracle数据库之Object的Access方法和结合方法》PPT视频
- git---Git中.gitignore配置
- MS08067 第一期 “恶意代码分析”实战班 12.17号开班~
- Pascal 基础教程
- 服务器搬迁方案_网站云服务器迁移方案需要注意什么?
- con和com开头单词
- matlab如何模拟数字舵机,模拟舵机和数字舵机区别
- VCIP2020:SCC编码工具的优化实现
- ae字体预设下载_AE超强文字预设包(附插件和教程)Videohive 2D Text Preset Pack for Animation Composer Plug-in...
- POI导出word单元格合并
- 每日一结(11.1)
- 腾讯地图的引用html
- linux下deb安装包的运行
- VMWare安装Win10虚拟机