Difference

To identify the people with blond hair who don't have blue eyes, we can use the difference() method:

>>> blond_hair.difference(blue_eyes)
{'Joshua', 'Mia'}

This finds all the elements which are in the first set which are not in the second set.

This is non-commutative because the people with blond hair who don't have blue eyes are not the same as the people who have blue eyes but don't have blond hair:

>>> blond_hair.difference(blue_eyes) == blue_eyes.difference(blond_hair)
False
..................Content has been hidden....................

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