Opposite of set.intersection in python? -
in python can use a.intersection(b)
find items common both sets.
is there way disjoint opposite version of this? items not common both a
, b
; unique items in a
unioned unique items in b
?
you looking symmetric difference; elements appear in set or in set b, not both:
a.symmetric_difference(b)
from set.symmetric_difference()
method documentation:
return new set elements in either set or other not both.
you can use ^
operator too, if both a
, b
sets:
a ^ b
while set.symmetric_difference()
takes iterable other argument.
the output equivalent of (a | b) - (a & b)
, union of both sets minus intersection of both sets.
Comments
Post a Comment