python 差异表达

If there are two sets A and B, then the difference between A and B (A-B) is a new set of elements that are present in A but not in B.

如果存在两个集合A和B,则A和B之间的差异(AB)是A中存在但B中不存在的一组新元素。

Following image depicts the set difference in mathematical terms.

下图以数学术语描述了设置差异。

Set Difference

设置差异

Python设置差异 (Python Set Difference)

Python set class has difference() function that returns the difference of two or more sets as a new set.

Python set类具有difference()函数,该函数将两个或多个set的差作为新set返回。

Let’s look at some examples of python set difference() function.

让我们看一些python set Difference()函数的示例。

set1 = {1, 2, 3, 4}
set2 = {2, 3, 5, 6}
set3 = {3, 4, 6, 7}print(set1.difference(set2))
print(set2.difference(set3))
print(set3.difference(set1))

Output:

输出:

{1, 4}
{2, 5}
{6, 7}

The output is same as shown in the first image explaining set difference.

输出与第一张图片中显示的设置差异相同。

Python Set Difference

Python设置差异

Let’s look at another example where we will get the difference between multiple sets.

让我们看另一个例子,我们将获得多个集合之间的差异。

print(set1.difference(set2, set3))

Output: {1}

输出: {1}

Since set difference() function returns a new set, we can take the set difference by a chain of difference() function calls too.

由于set Difference()函数返回一个新的集合,因此我们也可以通过一连串的difference()函数调用来获取集合差异。

print(set1.difference(set2).difference(set3))

Output: {1}

输出: {1}

GitHub Repository.GitHub存储库中检出完整的python脚本和更多Python示例。

Reference: Official Documentation

参考: 官方文档

翻译自: https://www.journaldev.com/24683/python-set-difference

python 差异表达

python 差异表达_Python设置差异相关推荐

  1. python检查_python设置检查点简单实现

    说检查点,其实就是对过去历史的记录,可以认为是log.不过这里进行了简化.举例来说,我现在又一段文本.文本里放有一堆堆的链接地址.我现在的任务是下载那些地址 中的内容.另外因为网络的问题或者网站的问题 ...

  2. python 交集_Python设置交集

    python 交集 The intersection (A∩B) of two sets A and B is the set that contains all the elements commo ...

  3. python度量学习_Python的差异度量

    python度量学习 Hi folks, welcome back to my new edition of the blog, thank you so much for your love and ...

  4. python excel 单元格格式_python设置单元格数值格式

    python xlwt如何设置单元格格式 python xlwt模块怎么设置excel单元格的属性 如图,默认是general.我想写入的时候就是Text类型.请问应该怎么做. from xlwt i ...

  5. python设置默认utf8编码_Python设置默认编码为utf8的方法

    本文实例讲述了python设置默认编码为utf8的方法.分享给大家供大家参考,具体如下: 这是Python的编码问题,设置python的默认编码为utf8 python安装目录:/etc/python ...

  6. python坐标轴刻度设置_Python Matplotlib 设置x/y坐标轴刻度

    刻度设置 参考文档: xticks 命令 yticks 命令 以xticks为例: matplotlib.pyplot.xticks(args, *kwargs) 获取或者设置当前刻度位置和文本的 x ...

  7. python权限管理设置_python权限管理框架

    Python生成管理员权限的可执行程序 如何使用pyinstaller或者其他生成一个有管理员权限的可执行程序,生成的我也遇到这个问题了. Python权限修饰正确的是? A. 标识符开头无下划线,该 ...

  8. python设置编码格式_python如何统一编码格式UltraEdit环境python语法高亮设置

    我一直在用ultraedit看zope3的源代码.语法高亮设置可参考www.ultraedit.com UltraEdit是一个很好的工具,但是默认不支持Python的语法高亮,下面是一个现成的Wor ...

  9. python全局变量在哪创建_python设置全局变量

    python中怎么定义全局变量 复制代码 count = 0 def Fuc(count): print count count += 1 for i in range(0, 10): Fuc(cou ...

最新文章

  1. 【网络爬虫】(1) 网络请求,urllib库介绍
  2. 手把手教你写移动端瀑布流控件布局篇
  3. SQL触发器实例(上)
  4. Unity中有两种Animation Clip
  5. Linux配置Java,kafka,Hadoop等环境变量
  6. TeX 家族(TeX, pdfTeX, XeTeX, LuaTeX, LaTeX, pdfLaTeX, XeLaTeX …)
  7. 小黑小波比.Ubuntu下的截图
  8. Pedestrian Identification (2) ——研究现状总结
  9. 龙果学院mysql分布式集群代码_龙果学院-MySQL大型分布式集群解决方案
  10. Python--day48--ORM框架SQLAlchemy操作表
  11. python正则表达式生成器_Python学习之路-装饰器生成器正则表达式
  12. 关于有类路由协议和无类路由协议
  13. Intel 64/x86_64/IA-32/x86处理器 - 通用指令(8) - 杂项指令 用户态扩展状态指令 随机数生成指令
  14. 使用路由和远程访问服务为Hyper-V中虚拟机实现NAT上网
  15. Win8Metro(C#)数字图像处理--2.18图像平移变换
  16. 2017 让机器给我们干活
  17. mysql 小时数列,MySql时区问题
  18. linux中,使用cat、head、tail命令显示文件指定行
  19. c++ 工厂模式_Java面试专题之五:设计模式学习,详细分析工厂方法模式
  20. ​​​​​​亲测有效|强制删除电脑上无法删除的文件和文件夹

热门文章

  1. atom编辑器 apm指令配置代理
  2. 做一款仿映客的直播App?看我就够了
  3. iOS ChildViewController与View
  4. 关于findViewById返回空指针的错误
  5. SQL语法集锦一:SQL语句实现表的横向聚合
  6. params 有什么用?
  7. 操作系统和语言的关系(转载)
  8. centos下不重装php——给PHP添加新扩展库
  9. hdu 4059 The Boss on Mars 容斥
  10. MacOs终端忽略大小写