Symmetric difference

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
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset