如何添加两组并删除重复项
>>> 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)
尝试这个:
>>> 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'])