Union

To find all the people with blond hair, blue eyes or both, we can use the union() method:

>>> blue_eyes.union(blond_hair)
{'Olivia', 'Jack', 'Joshua', 'Harry', 'Mia', 'Amelia', 'Lily'}

Set union collects together all of the elements which are in either or both sets.

We can demonstrate that union() is a commutative operation (that is, we can swap the order of the operands) using the value equality operator to check for equivalence of the resulting sets:

>>> blue_eyes.union(blond_hair) == blond_hair.union(blue_eyes)
True

 

..................Content has been hidden....................

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