Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Set basics
Relationships between sets
12. Using union()


Fantastic! We can use union() in a similar way:

kate_fav_movies = {'Halloween', 'A Star Is Born', 'Hocus Pocus'}
alan_fav_movies = {'A Star Is Born', 'The Lion King', 'Harry Potter'}
common_fav_movies = kate_fav_movies.union(alan_fav_movies)
print('Together, Alan and Kate like the following movies:', common_fav_movies)

The union() function creates a set that contains elements from both sets, as shown in the diagram:

You can also use this abbreviated notation:

kate_fav_movies | alan_fav_movies


XYC Corp. has some employees in cities A and B, as shown in the template code. Some of the employees work in both cities.

Your task is to create a union set from cities A and B and print the following sentence:

There are {x} employees in cities A and B.

Instead of {x}, provide the total number of unique employees in both cities.

Note: you can use len(set) to get the number of elements in a set.

Stuck? Here's a hint!