全部书籍

专业

应用 关于 Coach 登录 开始阅读

书籍暂未推出简体中文版——当前显示英文版。

Computer Science · 术语表

什么是 Set (Python type)?

又称: set (type)

Definition 2.6 High School Computer Science · 第 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.

示例

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.

在原文中阅读 →