Set algebra operations

Perhaps the most useful aspect of the set type is the group of powerful set algebra operations which are provided. These allow us to easily compute set unions, set differences, and set intersections, and to evaluate whether two sets have subset, superset, or disjoint relations.

To demonstrate these methods, we'll construct some sets of people according to various phenotypes:

>>> blue_eyes = {'Olivia', 'Harry', 'Lily', 'Jack', 'Amelia'}
>>> blond_hair = {'Harry', 'Jack', 'Amelia', 'Mia', 'Joshua'}
>>> smell_hcn = {'Harry', 'Amelia'}
>>> taste_ptc = {'Harry', 'Lily', 'Amelia', 'Lola'}
>>> o_blood = {'Mia', 'Joshua', 'Lily', 'Olivia'}
>>> b_blood = {'Amelia', 'Jack'}
>>> a_blood = {'Harry'}
>>> ab_blood = {'Joshua', 'Lola'}
Figure 5.22: Set algebra operations
..................Content has been hidden....................

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