Python学习笔记(求交集,并集.....)


>>> x = set('abcde')
>>> y = set('bdxyz')

>>> x
set(['a', 'c', 'b', 'e', 'd'])                    # 2.6 display format

>>> 'e' in x                                      # Membership
True


>>> x – y                                         # Difference
set(['a', 'c', 'e'])


>>> x | y                                         # Union
set(['a', 'c', 'b', 'e', 'd', 'y', 'x', 'z'])


>>> x & y                                         # Intersection
set(['b', 'd'])


>>> x ^ y                                         # Symmetric difference (XOR)
set(['a', 'c', 'e', 'y', 'x', 'z'])


>>> x > y, x < y                                  # Superset, subset
(False, False)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM