Sets and Set Operations
Build sets and perform union, intersection, and difference.
Introduction
Sets are unordered collections of unique hashable elements. They are optimized for membership testing and mathematical set operations.
Creating a Set
s = {1, 2, 3} or s = set([1, 2, 2, 3]) — duplicates are removed automatically. {} creates an empty DICT, not a set.
s = {1, 2, 2, 3}
print(s) # {1, 2, 3}
empty = set()
print(type(empty))All lessons in this course
- Dictionary Basics
- Dictionary Methods
- Sets and Set Operations
- Dictionary Comprehensions