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

## Chapter 5 — The source print follows the list

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

Lesson 05. Map, example, EX051.

```mermaid
flowchart TD
  L["Four source tuples, written order"] --> D["deps grows by first sighting"]
  D --> P["Two dependency lines, then the independent line"]
  P --> Q{"Did a sort pick the inbox line?"}
  Q -->|No| K["Keep the embedded print"]
```

The walk follows `sources`. Nothing in the file sorts the names.

### Logical drawing

```text
coordinator inbox: CCC alerts, Donation platform notices -> SINGLE POINT OF FAILURE
form owner Sam: Volunteer reports -> SINGLE POINT OF FAILURE
independent sources: ['National charity advisories']
```
<!-- open-cyber-academy:lesson-figures:end ch-05 -->

### Learning outcomes

After this chapter, you should be able to:

1. Name the order `sources` is written in.
2. Say why the inbox line prints before the form line.
3. Refuse a print that leads with the national advisories.

### 5.1 Keys appear when they are first needed. Names append after that.

`lab_sources.py` stores four tuples. Each tuple is a source name, a channel, and a list of needs. The first tuple is CCC alerts, with the need `coordinator inbox`. The second is National charity advisories, with an empty needs list. The third is Donation platform notices, again needing `coordinator inbox`. The fourth is Volunteer reports, needing `form owner Sam`. The loop walks that written order. It never calls `sorted`.

The mapping starts blank.

A key opens at the earliest requirement.

Alerts open the mailbox key.

The donation-page record appends there, so the length is two.

The shared-form record opens the other key alone.

`items()` emits creation sequence.

Mailbox comes before the other key.

The web-page record adds no key.

Its title sits at the bottom because a later statement prints it.

A later decision to name a deputy is a sentence in the notes. It does not reorder these three lines.

| What the walk uses | What it does not use |
|---|---|
| Position in `sources` | An alphabetical sort |
| First sighting of a need | A severity score |
| Append, for a repeated need | A staff directory |

### 5.2 Worked example

| Offered result | What produced it | Decision |
|---|---|---|
| Inbox line, then form line, then the independent line | Insertion, then one extra print | Keep |
| CCC alerts before Donation platform notices | Append order inside the inbox list | Keep |
| "The script sorted by channel." | No sort is called | Refuse |
| "National advisories print first because they are safest." | That tuple is not a `deps` key | Refuse |

> **Synthetic case.** These three lines are the only source-lab output.

### Errors and limits

Do not rebuild `sources` so that a preferred channel prints first.

### Apply

- **EX051 — List order.** The print names the coordinator inbox, then form owner Sam, then the national advisories. May a preference for the independent source, or a later deputy, replace that order? *Rubric:* 3 = no; the dependency lines follow first sighting; names append in source order; the independent line is the last print; do not sort the script;; 2 = the three lines stay and the deputy stays prose;; 1 = one line;; 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 dependency lines follow first sighting, and names append in source order. The independent line is the last print. A later deputy does not reorder the script.
