利用python中集合的唯一性实现去重
作者:奔跑de蚂蚁 时间:2021-03-29 18:42:25
什么是集合
1.集合是一个可变容器
2.集合内的数据对象都是唯一的(不能重复)
3.集合是无序的存储结构,集合内的数据没有先后关系
4.集合是可迭代对象
5.集合相当于是只有键没有值得字典(键就是集合中的数据)
6.集合内的元素是不可变的
好了,集合咱们都了解了,现在开始我们的正文,
集合,用{ }表示,集合中所有元素具有唯一性
定义集合:
parame = {value01,value02,…} 或者 parame =set(value)
将list = [1,1,2,3,4,5,6]去重
list = [1,1,2,3,4,5,6]
temp = set() #创建一个空集合 使用temp = set(),若使用temp = {},则创建空字典
for i in list:
temp.add(i)
print(temp)
或者更为简便的方法
list = [1,1,2,3,4,5,6]
temp = set(list)
print(temp)
创建空列表: list = []
创建空元组:tuple = ()
创建空字典: dict = {}
创建空集合:set = set()
总结
以上所述是小编给大家介绍的利用python中集合的唯一性实现去重,希望对大家有所帮助!
来源:https://blog.csdn.net/adiungdc/article/details/100689601
标签:python,去重,集合
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
pyecharts实现数据可视化
2023-05-24 06:18:48
![](https://img.aspxhome.com/file/2023/9/114509_0s.png)
根据选择的checkbox列出选择的值
2008-07-30 12:56:00
![](https://img.aspxhome.com/file/UploadPic/20087/30/200873013437517s.jpg)
Python深入学习之对象的属性
2022-11-17 03:47:34
Python使用jpype模块调用jar包过程解析
2023-04-12 03:07:12
Python PyAutoGUI模块控制鼠标和键盘实现自动化任务详解
2021-07-16 07:40:40
![](https://img.aspxhome.com/file/2023/9/107619_0s.png)
python继承threading.Thread实现有返回值的子类实例
2023-06-07 19:01:15
Python中函数参数调用方式分析
2022-09-14 04:54:07
SQLServer 存储过程简介与使用方法
2009-07-07 14:06:00
Python 爬虫的原理
2023-01-18 21:05:35
![](https://img.aspxhome.com/file/2023/0/124780_0s.jpg)
Tesserocr库的正确安装方式
2023-12-26 17:19:34
![](https://img.aspxhome.com/file/2023/3/124363_0s.png)
10个顶级Python实用库推荐
2023-08-27 17:41:46
![](https://img.aspxhome.com/file/2023/8/65518_0s.jpg)
Oracle逗号分隔列转行实现方法
2011-01-04 20:13:00
Python+Selenium实现短视频热点爬取
2022-03-07 23:43:37
![](https://img.aspxhome.com/file/2023/1/86151_0s.jpg)
python list 合并连接字符串的方法
2021-12-18 09:35:30
结合OpenCV与TensorFlow进行人脸识别的实现
2021-07-06 08:44:28
![](https://img.aspxhome.com/file/2023/4/95824_0s.jpg)
Python反爬虫技术之防止IP地址被封杀的讲解
2022-05-09 10:44:12
![](https://img.aspxhome.com/file/2023/3/108123_0s.png)
Web前端应用十种常用技术
2010-09-01 20:46:00
![](https://img.aspxhome.com/file/UploadPic/20109/1/01-96s.jpg)
PHP echo()函数讲解
2023-06-05 18:50:54
![](https://img.aspxhome.com/file/2023/0/55390_0s.png)
Python名片管理系统+猜拳小游戏案例实现彩(色控制台版)
2021-10-26 03:52:44
![](https://img.aspxhome.com/file/2023/9/108049_0s.gif)
Python程序设计入门(5)类的使用简介
2023-01-21 06:27:56