Set Methods
set.symmetric_difference()
Keep members that occur on exactly one side, excluding those common to both. Repeated values in an iterable do not toggle membership repeatedly. Accepts exactly one other iterable. Returns a set result without changing the receiver. For an exact mutable set, the result is a separate outer set. The method accepts iterable inputs such as lists or generators, unlike the built-in ^ operator between sets. Elements used in hashing must be hashable. Input iteration can raise exceptions; no ordering is guaranteed.
Formal Syntax & Structure
python syntaxpython
items.symmetric_difference(other, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| other | Iterable[Hashable] | Iterable of candidate elements. |
Return Value
set
set containing the calculated members.
Working Example
Example Snippetpython
a = {"red", "green"}b = a.symmetric_difference(["green", "blue", "blue"])print(sorted(b))print(sorted(a))