June 2017
Beginner
352 pages
8h 39m
English
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
Read now
Unlock full access