码迷,mamicode.com
首页 > 其他好文 > 详细

set集合的差集的区别

时间:2018-11-15 11:03:21      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:style   差集   ret   coding   自己   set集合   print   的区别   集合   

 1 # coding=utf-8
 2 a = [1, 2]
 3 b = [2, 3, 4]
 4 
 5 s1 = set(a)
 6 s2 = set(b)
 7 
 8 ret1 = s1.difference(s2)
 9 ret2 = s1.symmetric_difference(s2)
10 
11 print(ret1)
12 print(ret2)

输出结果:

1 {1}
2 {1, 3, 4}

结论:

difference 是拿自己跟别人做比较得到一个返回结果

symmetric_difference 是自己跟别人做比较,然后别人也跟你做比较,把两者之间没有的返回给一个值。

 

set集合的差集的区别

标签:style   差集   ret   coding   自己   set集合   print   的区别   集合   

原文地址:https://www.cnblogs.com/py-web/p/9962107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!