Subset relationships

Figure 5.23:  Set relationships

In addition, three predicate methods are provided which tell us about the relationships between sets. We can check whether one set is a subset of another using the issubset() method. For example, to check whether all of the people who can smell hydrogen cyanide also have blond hair:

>>> smell_hcn.issubset(blond_hair)
True

This checks that all the elements of the first set are also present in the second set.

To test whether all the people who can taste phenylthiocarbamide (PTC) can also smell hydrogen cyanide use the issuperset() method:

>>> taste_ptc.issuperset(smell_hcn)
True

This checks that all the elements of the second set are present in the first set.

A representation of PTC. It has the unusual property that it either tastes very bitter or is virtually tasteless, depending on the genetics of the taster:

Figure 5.24: Representation of phenylthiocarbamide

To test that two sets have no members in common, use the isdisjoint() method. For example, your blood type is either A or O, never both:

>>> a_blood.isdisjoint(o_blood)
True
..................Content has been hidden....................

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