Member-only story
How To Compare Two Sets in Python
Take advantage of built-in methods for easy comparisons

One of my favorite data types in Python is the set. Sets are super handy — most frequently being used to eliminate duplicate items in an iterable. However, sets can be used for more than a quick dupe eliminator.
Sets have their roots in discrete math—a branch that focuses on countable or distinguishable objects. The first way to observe and interact with sets is to compare them to one another.
This is reflected in Python’s natively available set methods. Before we dive into that, let’s cover a basic primer on creating sets.
Creating Sets in Python
To create a set, use curly braces with each element separated by a comma.
my_first_set = {1,2,3,4,5}
If you happen to duplicate an element, you’ll notice the set gracefully removes it without causing any sort of error.
my_first_set = {1,2,3,4,5,2}
print(my_first_set) # {1,2,3,4,5}
Make sure you don’t get sets confused with dictionaries, which are also enclosed with curly braces.
my_set = {1,2,3}
my_dict = {"term": "definition", "term2": "definition2"}