博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
017_set
阅读量:5282 次
发布时间:2019-06-14

本文共 930 字,大约阅读时间需要 3 分钟。

#!/usr/bin/env python # Author:liujun list1 = [1,4,5,7,3,6,7,9] list1 = set(list1) # set is unordered list2 = set([2,6,0,66,22,8,4]) print(list1.intersection(list2)) print(list1 & list2) # Extract the intersection of the two lists print(list1.union(list2)) print(list2 | list1) # Extract the union of the two lists print(list1.difference(list2)) print(list1 - list2) # Extract the difference of the two lists print(list1.issubset(list2)) # Determine whether a list is a sutset of another print(list1.issuperset(list2)) # Determine whether a list is a parent of another print(list1.symmetric_difference(list2)) print(list1 ^ list2) # Extract symmetric_difference of the two lists list1.add(555) # Add single element list1.update([55,66,88,99]) # Add multiple elements list1.pop() # Return and remove an arbitrary set element list1.discard(888) # Remove the element print(list1)

转载于:https://www.cnblogs.com/liujun5319/p/9588956.html

你可能感兴趣的文章
响应式布局
查看>>
python 面试题
查看>>
linux磁盘挂载流程
查看>>
LFI、RFI、PHP封装协议安全问题学习
查看>>
[ES2018] Two ways to write for-await-of
查看>>
[React] Understanding setState in componentDidMount to Measure Elements Without Transient UI State
查看>>
[Redux] Refactoring the Entry Point
查看>>
再次深入探索datasource问题?
查看>>
agc007C - Pushing Balls(期望 等差数列)
查看>>
洛谷 P2679 子串
查看>>
Hibernate Foreign Key exception
查看>>
【BZOJ4849】[Neerc2016]Mole Tunnels 模拟费用流
查看>>
【BZOJ2320】最多重复子串 调和级数+hash
查看>>
UNI-APP开发微信公众号(H5)JSSDK使用
查看>>
2057The Lost House
查看>>
springmvc 拦截器,不拦截jsp文件
查看>>
http状态码汇总
查看>>
.net json 和 Datatable 相互转化
查看>>
中位数与顺序统计量
查看>>
Linux 工具套件 —— binutils、readelf
查看>>