python-set
来源:互联网 发布:想从事网络方面的工作 编辑:程序博客网 时间:2024/06/05 13:21
#!/usr/bin/python
# -*- coding:utf-8 -*-
#集合的交集/并集/差补/对称差分
a=set((1,2,3,"a","b"))
b=set((1,2,4,"a","c"))
print a & b #交集:等同于a.interseciton(b)
print a | b #补集:等同于a.union(b)
print a-b #差补:d等同于a.diffrence(b)在a集合中去掉所有与b集合中相同的元素 // 只在a中保留b中没有的结合元素
print a^b #对称差分:找出两个结合中,只属于集合a或者集合b的元素
# -*- coding:utf-8 -*-
#集合的交集/并集/差补/对称差分
a=set((1,2,3,"a","b"))
b=set((1,2,4,"a","c"))
print a & b #交集:等同于a.interseciton(b)
print a | b #补集:等同于a.union(b)
print a-b #差补:d等同于a.diffrence(b)在a集合中去掉所有与b集合中相同的元素 // 只在a中保留b中没有的结合元素
print a^b #对称差分:找出两个结合中,只属于集合a或者集合b的元素
运行结果:
orangemarmot ODW [:~/python/python-scripts] 1206$ python set.py
set(['a', 1, 2])
set(['a', 1, 2, 3, 4, 'c', 'b'])
set([3, 'b'])
set(['c', 3, 4, 'b'])
==========
>>> a=set((1,2,3,"a","b"))
>>> set(a)
set(['a', 1, 2, 3, 'b'])
>>> b=set((1,2,4,"a","c"))
>>> a
set(['a', 1, 2, 3, 'b'])
>>> b
set(['a', 1, 2, 4, 'c'])
>>> a & b
set(['a', 1, 2])
>>> a.intersection(b)
set(['a', 1, 2])
>>> a | b
set(['a', 1, 2, 3, 4, 'c', 'b'])
>>> a.union(b)
set(['a', 1, 2, 3, 4, 'c', 'b'])
>>> a-b
set([3, 'b'])
>>> a^b
set(['c', 3, 4, 'b'])
阅读全文
0 0
- Python Set
- python set
- python set
- python--set
- python set
- python set
- python set
- Python---set
- Python set
- python set
- python set
- python set
- python-set
- Python set
- python set()
- python set
- Python Set
- python ---- set
- c语言中键值输入
- Java整数与字符串转换
- Groovy使用多赋值
- RecyclerView特性和使用
- HDU 6016 Count the Sheep (思路)
- python-set
- Jquery EasyUI后台基本用法总结
- ios开发蓝牙 BLE
- 【web前端自动化工作环境配置】8. 依赖管理工具bower的基本用法
- 生产环境使用elasticsearch遇到的一些问题以及解决方法(不断更新)
- js 获取屏幕各种宽高的方法
- Mac 配置gradle环境
- React Native报Super expression error must either be null or a function错误分析
- iOS-Bluetooth-MFI&BLE