Python添加两个集合并删除重复元素

abc*_*abc 7 python python-2.7

如何添加两组并删除重复项

>>> a = set(['a', 'b', 'c'])
>>> b = set(['c', 'd', 'e'])
>>> c = a + b
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'set' and 'set'
>>>

Expected output:
c = set(['a','b','c', 'd', 'e']) 
Run Code Online (Sandbox Code Playgroud)

Del*_*ain 6

尝试这个:

>>> a = set(['a', 'b', 'c'])
>>> b = set(['c', 'd', 'e'])
>>> c = a.union(b)
Run Code Online (Sandbox Code Playgroud)

结果:

set(['a','b','c', 'd', 'e'])