Python set() built-in function

From the Python 3 documentation

Return a new set object, optionally with elements taken from iterable. set is a built-in class. See set and Set Types — set, frozenset for documentation about this class.

Introduction

The set() constructor creates a new set. A set is an unordered collection of unique elements. You can create an empty set, or create a set from an iterable.

Examples

Create an empty set:

my_set = set()
print(my_set)  # Output: set()

Create a set from a list (duplicates are removed):

my_list = [1, 2, 2, 3, 3, 3]
my_set = set(my_list)
print(my_set)  # Output: {1, 2, 3}

Subscribe to pythoncheatsheet.org

Join 16,702+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.