Union |
>>> s1 = set([1, 2, 3])
>>> s2 = set([3, 4, 5])
>>> print s1.union(s2)
set([1, 2, 3, 4, 5])
Intersection &
>>> s1 = set([1, 2, 3])
>>> s2 = set([3, 4, 5])
>>> print s1.intersection(s2)
set([3])Difference -
>>> s1 = set([1, 2, 3])
>>> s2 = set([3, 4, 5])
>>> print s1.difference(s2)
set([1, 2])Symmetric Difference ^
>>> s1 = set([1, 2, 3])
>>> s2 = set([3, 4, 5])
>>> print s1.symmetric_difference(s2)
set([1, 2, 4, 5])
Комментариев нет:
Отправить комментарий