如何添加两个集合并删除重复项
>>> 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'])
最佳答案
试试这个:
>>> a = set(['a', 'b', 'c'])
>>> b = set(['c', 'd', 'e'])
>>> c = a.union(b)
结果:
set(['a','b','c', 'd', 'e'])
关于Python添加两组并删除重复元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49227864/