Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Recap
Using sets to compute unique elements
Set operations
9. Multiple set operations
Simulating machines
Summary

Instruction

Great! So how would you create a set that is a union of multiple sets? Or an intersection of a few sets? Of course, using a & or | a couple of times would solve the problem. But it may not be obvious that you can use them multiple times in one line! For example:

new_set = set_1 & set_2 & set_3 & set_4

The new_set contains all the elements that are in each of the four sets (set_1, set_2, set_3, and set_4).

Of course, you can combine multiple operators, i.e.:

new_set = (set_1 | set_2) - set_3 - set_4

Now new_set contains all elements that are in set_1 or set_2 but not those in set_3 or set_4.

Exercise

Remember our volleyball_players and basketball_players sets? The sports hall's owner decided to rent the hall out to football players (football_players) as well. Now the owner wonders how many new players will use the hall and how many players will play there in total.

Create an all_players set and a new_players set. Then, count the number of elements in these sets and print:

There are {} players using the hall, {} of which are new players.