all Python 3Sets (set)function
frozenset.symmetric_difference
frozenset
Return a new frozenset — the symmetric difference of the two sets.
Syntax
f.symmetric_difference(other)
The symmetric difference keeps items that occur in exactly one of the sets — the union minus the intersection. Unlike union() or difference(), this method takes exactly one argument, so three sets cannot be folded in a single call. The ^ operator computes the same result but requires sets on both sides.
Examples
print(frozenset({1, 2}).symmetric_difference({2, 3})) # → frozenset({1, 3})
print(frozenset({1, 2}).symmetric_difference({3, 4})) # → frozenset({1, 2, 3, 4})
print(frozenset({1, 2, 3}).symmetric_difference([3, 4])) # → frozenset({1, 2, 4})
print(sorted(frozenset('abc').symmetric_difference('bcd'))) # → ['a', 'd']
print(frozenset({1, 2}).symmetric_difference({1, 2})) # → frozenset()
print(frozenset({1, 2}) ^ {2, 3}) # → frozenset({1, 3})
See also
Open in the full glossarydocs.python.orgReport an inaccuracy