これは入力です:
x = [{1, 2, 3}, {2, 3, 4}, {3, 4, 5}]
出力は次のようになります。
{1, 2, 3, 4, 5}
使用しようとしましset().union(x)
たが、これは私が得ているエラーです:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'set'
これは入力です:
x = [{1, 2, 3}, {2, 3, 4}, {3, 4, 5}]
出力は次のようになります。
{1, 2, 3, 4, 5}
使用しようとしましset().union(x)
たが、これは私が得ているエラーです:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'set'
の署名はset.union
ですunion(other, ...)
。リストからセットを展開します。
In [6]: set.union(*x)
Out[6]: {1, 2, 3, 4, 5}