Understand the data structure of sets, how to use them, and how they differ from lists.

Sets are linear data structures very similar to lists. However, they do have a few notable differences.

What is a Set? #

Just like a list, a set is a linear data structure that contains multiple elements. However, sets are different from lists because:

  • Sets have no concept of ordering, meaning there is no such thing as “the third element” in a set.
  • Sets cannot contain duplicates; you cannot have a set that, for instance, contains 42 twice.

Both these properties of sets have implications for programming with them that you should be aware of when using them.

Creating a Set #

The way to create a set should look familiar to you:

Get hands-on with 1000+ tech skills courses.