Set
Python's set type represents an unordered collection of unique, hashable elements. Frozensets are immutable versions of sets. This guide covers set operations and methods. The guide walks through Creating Sets, Set Operations, Set Comparisons, Mutating Sets, Frozenset, Set Comprehensions. Use curly braces `{1, 2, 3}` or `set([1, 2, 3])` to create a set. An empty set must be created with `set()`, not `{}` (which creates an empty dict). `frozenset([1, 2, 3])` creates an immutable frozenset that can be used as a dictionary key. `a | b` or `a.union(b)` returns the union. `a & b` or `a.intersection(b)` returns common elements. `a - b` or `a.difference(b)` returns elements in a but not b. `a ^ b` or `a.symmetric_difference(b)` returns elements in either but not both. `a == b` checks equality. `a = b` or `a.issuperset(b)` checks superset. `a.isdisjoint(b)` returns True if they have no elements in common. The guide is organized into 6 sections that build on each other, each pairing a prose explanation with runnable code.