学习目标
- 列表List
- 列表推导式
- tuple元组
- set 集合
- dict 字典
- 实战项目
列表List
list 是一种有序的集合,可以随时的添加、删除一个元素
创建list
创建一个list,只有逗号分割不同的数据,然后使用方括号扩起来。list 中的元素可以是不同的数据类型


访问list 数值

list 更新

我们希望被添加到list 中的数据,每个元素做为添加对象.

注意:
list 集合 extend 和 append 的区别
list 删除

list 运算符

再次强调: extend 、append 的区别
list 中函数


上边的内容不满足我们的业务需求,我们更佳希望是按照数量进行排序

list 的列表推导式

这块代码有哪些可以进一步优化的呢?
1.一个简单的顾虑操作,5行代码才完成此功能
2.更佳简单、效果可视化感觉最好的方式处理?

tuple 元组
tuple 和 list 非常类似,但是有区别
- tuple 初始化之后不能修改了
- tuple 没有append insert 函数操作原来的tuple
- tuple 同样提供的索引获取数据函数
- 建议list 和tuple ,一般情况能用tuple 的就不用list ,使得我们的操作更佳安全

读取tuple 类型的数据

更新tuple
tuple 不可变,不能修改,和list 的区别

删除 tuple
不能删除,tuple 不能变

tuple 运算符

tuple 内置函数

set
是一个无序不重复的元素的集合。基本功能: 消除重复数据、关系测试。 set和dict 类似,但是set 不存在value
set 创建

add(...)
| Add an element to a set. |
| This has no effect if the element is already present.

remove(self, value, /)
| Remove first occurrence of value. |
| Raises ValueError if the value is not present.

union(...)
| Return the union of sets as a new set. |
| (i.e. all elements that are in either set.)

intersection(...)
| Return the intersection of two sets as a new set. |
| (i.e. all elements that are in both sets.)

difference(...)
| Return the difference of two or more sets as a new set. |
| (i.e. all elements that are in this set but not the others.)

dict 字段
字典是一种可变容器模型,可以存储任意类型对象。
语法: _dict = {key1:value1,key2:value2}
dict 创建和访问

dict 新增或者修改

dict 遍历

实战项目
序列中的数据去重

序列中单词长度长于3 返回

可以使用列表推导式来解决该问题。

两个list 序列相同的元素输出

词频统计

还有没有更加简单的方法呢?

两个list 列表,建立一一对应的关系

最后,让我们一起加油!!!










