Alle boeken

Professioneel

Apps Over Coach Inloggen Begin met lezen

Computer Science · Begrippenlijst

Wat is Set (Python type)?

Ook bekend als: set (type)

Definition 2.6 High School Computer Science · Hoofdstuk 2 — Tuples, Sets and Comprehensions

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.

The two members’ sets of books, with the counts printed by the run (the five shared books are 16, 57, 62, 71 and 75). The union holds 6 + 11 - 5 = 12 books: the shared ones would otherwise be counted twice.
The two members’ sets of books, with the counts printed by the run (the five shared books are 16, 57, 62, 71 and 75). The union holds 6+11−5=126 + 11 - 5 = 12 books: the shared ones would otherwise be counted twice.

Voorbeelden

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.

Lees in het hoofdstuk →