<a id="ch-05"></a>

## Chapter 5 — The sharing print is one filter

<!-- open-cyber-academy:lesson-figures:start ch-05 -->
### Lesson map

Lesson 05. Map, example, EX051.

```mermaid
flowchart TD
  T["Eight triples"] --> F["setting not in the allowed set"]
  T --> N["count of True flags"]
  F --> B["three names, list order"]
  N --> S["sensitive 5"]
  B --> Q{"Is the filter a later census?"}
  S --> Q
  Q -->|No| K["Keep the embedded print"]
```

One list. One membership test. Three printed numbers.

### Logical drawing

```text
items 8, sensitive 5, shared too widely 3
  patient-letters/: anyone-with-link
  invoices/: anyone-with-link
  old-backup.zip: anyone-with-link
```
<!-- open-cyber-academy:lesson-figures:end ch-05 -->

### Learning outcomes

After this chapter, you should be able to:

1. Name the three reductions the sharing script actually computes.
2. Keep list order distinct from the April incident.
3. Refuse a note that replaces this export with a later folder state.

### 5.1 Three reductions, and no walk inside a folder.

`lab_sharing.py` stores eight triples. Each triple is a name, a setting string, and a Boolean. The names are the top-level storage items only. A file inside `patient-letters/` is not a fourth field and cannot change `len(items)`.

The Boolean sum is `sum(1 for i in items if i[2])`. Python counts `True` as one, so the five sensitive flags print as `sensitive 5`. That sum does not look at the setting string. `referrals/` and `booking-app-config` contribute to the five and do not contribute to the failure list.

The failure list is a comprehension: keep the pair when the setting is absent from `allowed[sens]`. `allowed[True]` holds `staff` and `admins`. `allowed[False]` holds those two strings plus `public`. The comprehension does not sort. `patient-letters/` is printed first because it is the first failing triple, not because a patient mentioned it. `rota.xlsx`, `price-list.pdf`, `logo.png`, `referrals/`, and `booking-app-config` are tested and kept out of `bad`.

A later staff-only change is a decision-log sentence. It is not a fourth run, and it does not edit these eight triples. Printing `shared too widely 2` would require deleting a triple this file still contains.

### 5.2 Worked example

| Offered result | What produced it | Decision |
|---|---|---|
| `items 8, sensitive 5, shared too widely 3` | Length, Boolean sum, filter length | Keep |
| The three names in list order | The comprehension, unsorted | Keep |
| "The script now omits patient-letters." | No edit of the eight triples | Refuse |
| "The filter counted files inside the folders." | The list has no child rows | Refuse |

> **Synthetic case.** The eight triples are the only sharing output.

### Errors and limits

Directory children stay uncounted. Do not repair the export so that it matches the afternoon change.

### Apply

- **EX051 — One filter.** The print says 8 items, 5 sensitive, and 3 shared too widely, then names patient-letters, invoices, and old-backup.zip. May a later staff-only change, or a count of files inside those folders, replace that print? *Rubric:* 3 = no; the eight triples stay; the Boolean sum stays 5; the filter stays 3, in list order; do not edit the script;; 2 = the print stays and the later change stays prose;; 1 = one number;; 0 = none.

<!-- open-cyber-academy:chapter-navigation:start ch-05 -->
### Continue studying — lesson 05 (chapter 05 of 20)

[← Chapter 04](#ch-04) · [Course chapter index](../SUBJECTS.md) · [Chapter 06 →](#ch-06)

Continue to the next authored lesson.
<!-- open-cyber-academy:chapter-navigation:end -->

## Worked answers

<a id="answer-ex051"></a>
**EX051.** No. The eight triples stay. The Boolean sum stays 5. The filter stays 3, in list order: patient-letters, invoices, and old-backup.zip. A later staff-only change and any count of files inside folders stay outside the script.
