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)

你可能感兴趣的:(python求解列表元素的交集、并集和异或)