A set is a collection of values without order and without repeats. It is written between braces, {1, 2, 3}, or built from any sequence with set(t); the empty set is set(), since {} is an empty dictionary. The test x in s says whether x belongs to s, s.add(x) adds an element, and the operators &, | and - give the intersection, the union and the difference of two sets.
উদাহরণ
Example 2.8 (The books of a member, in one line)
The function books_of of the town listing is the set comprehension {loan["book_id"] for loan in loans if loan["member_id"] == member}: for each loan, if it is the member’s, put its book in the set.