Search⌘ K
AI Features

Sets

Explore the different types of sets in Python including mutable sets and immutable frozensets. Understand their creation, use cases, and key operations like union and intersection to write efficient, meaningful code using Python's built-in data structures.

This lesson lists different implementations of a set provided by Python 3 and explains when to use which built-in support.

Introduction

A set is a collection of items that does not allow duplicates. It’s an unordered collection.

⚠️ Note: In case you forget, the expression of a set involves curly-braces {} in Python. To create an empty set, we call the set() function. Using {} without any values in it will create a dictionary, not a set.

Types of sets

Mutable set with set

The set() creates a mutable structure. ...