June 2017
Beginner
352 pages
8h 39m
English
However, if we want to determine which people have exclusively blond hair or blue eyes, but not both, we can use the symmetric_difference() method:
>>> blond_hair.symmetric_difference(blue_eyes){'Olivia', 'Joshua', 'Mia', 'Lily'}
This collects all the elements which are in the first set or the second set, but not both.
As you can tell from the name, symmetric_difference() is indeed commutative:
>>> blond_hair.symmetric_difference(blue_eyes) == blue_eyes.symmetric_difference(blond_hair)True
Read now
Unlock full access