Psst! Check what courses we have in our offer, and get them all here to save $727. Tick-tock—this deal ends on 3/21.
Introduction
Set basics
10. Using the in operator with sets
Relationships between sets
Summary

Instruction

Well done! You can also check if an element is present in a set using the in operator. Let's see how this works:

favorite_movies = {'Halloween', 'A Star Is Born', 'Hocus Pocus'}

if 'Halloween' in favorite_movies:
  print('Excellent! I love "Halloween" too!')

In the code above, we check for the string 'Halloween' inside the favorite_movies set.

Exercise

We've got a few newcomers to the XYC Corp.! Some of them work in the new branch, while some don't. You are now given two variables:

  • new_branch_employees – a set you already know well,
  • newcomers – a list of all the new employees in XYC Corp.

Your task is to calculate how many of these new employees work in the new branch and print the following:

{x} out of {y} newcomers work in the new branch!

Stuck? Here's a hint!

Iterate over the newcomers list. For each element, use the in operator to check if it exists in the set.