Intersection

To find all the people with blond hair and blue eyes, we can use the intersection() method:

>>> blue_eyes.intersection(blond_hair)
{'Amelia', 'Jack', 'Harry'}

Which collects together only the elements which are present in both sets. This is also commutative:

>>> blue_eyes.intersection(blond_hair) == blond_hair.intersection(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