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)

posted @ 2012-02-02 11:33  谷安  阅读(8399)  评论(0编辑  收藏  举报