Problem Solving: Difference between Sets

Learn how to calculate the difference between sets.

In this lesson, we’ll compute the difference of two sets where the difference set A-B is the set of all elements that are in A but not in B. For example, if A = {1, 4, 7} and B = {7, 8}, then A-B = {1, 4}. In this case, element 7 is present in both A and B, so it is not included in A-B. So the resulting set only includes elements 1 and 4, which are unique to set A.

Instruction: Use the following playground to write the complete code for the task in this lesson.

We have already added code for loading, sorting, and displaying sets, so you do not need to include that.

Get hands-on with 1200+ tech skills courses.