unionとintersection

http://blog.livedoor.jp/dankogai/archives/51441112.html

一方、Pythonはsetの演算子を定義した。

>>> a = "0 1 2 3 4 5 6 7 8 9".split()
>>> b = "0 2 4 6 8 10 12 14 16 18".split()
>>> print set(a) & set(b)
set(['0', '8', '2', '4', '6'])
>>> print set(a) | set(b)
set(['10', '12', '14', '16', '18', '1', '0', '3', '2', '5', '4', '7', '6', '9', '8'])
このブログに乗せているコードは引用を除き CC0 1.0 で提供します。