Next / Previous / Contents / TCC Help System / NM Tech homepage

8. Types set and frozenset: Set types

Mathematically speaking, a set is an unordered collection of zero or more distinct elements. Python has two set types that represent this mathematical abstraction. Use these types when you care only about whether something is a member of the set or not, and you don't need them to be in any specific order.

The elements of a Python set must be immutable. In particular, you can't have list or dictionary elements in a set.

Most operations on sets work with both set and frozenset types.

To create a set or frozenset, see Section 13.33, “set(): Create an algebraic set” and Section 13.14, “frozenset(): Create a frozen set”.

A number of functions that work on sequences also work on sets. In each case, the set is converted to a list before being passed to the function.