Lesson map
Lesson 09. Map, example, EX055.
flowchart TD
I["Dict insertion: model, tokenizer, config"] --> S["sorted(received) reorders the names"]
S --> P["config.yaml prints first"]
The check's order is alphabetical. The JSON object's order is not.
Logical drawing
config.yaml MISMATCH
model.bin MISMATCH
tokenizer.json OK
Learning outcomes
After this chapter, you should be able to:
- Read the three status lines from top to bottom.
- Explain why config.yaml leads even though it was inserted last.
- Refuse a reading that treats the JSON order as the check order.
9.1 The loop iterates sorted(received), and the format width is 15.
sorted(received.items()) orders by the file name. config.yaml sorts before model.bin, and model.bin sorts before tokenizer.json. That is why the status block begins with the config line. The JSON object above it was built from the manifest dict, whose insertion order is model, tokenizer, config. Two orders appear in one print. They answer different questions.
The format is f"{n:15s} {'OK' if ok else 'MISMATCH'}". The name occupies 15 characters, then a space, then the word. config.yaml is 11 characters, so four pad spaces sit inside the width and one more space separates the word. tokenizer.json is 14 characters, so the pad inside the width is a single space and the separator adds another. Tokenizer equality against manifest[n] is what prints OK. config.yaml and model.bin each recompute a hex string that differs from the stored digest, so those status words fail. Alphabetical position does not assign the failure.
Lesson table; scroll horizontally to read all columns →
| Order | Sequence |
|---|---|
| JSON object | model.bin, tokenizer.json, config.yaml |
| Status lines | config.yaml, model.bin, tokenizer.json |
| What picks OK | Full digest equality, not the row's position |
9.2 Worked example
Lesson table; scroll horizontally to read all columns →
| Reading | Decision |
|---|---|
| "The first status line is config.yaml, and it says MISMATCH." | Keep |
| "Tokenizer is last and says OK." | Keep |
| "The JSON listed model.bin first, so the check did too." | Refuse |
| "OK means the prefix was 16 characters." | Refuse; OK means the full digests matched |
Synthetic case. Sorting these three names is a property of the loop, not of a model registry.
Errors and limits
Reading the status block as if it followed insertion order assigns the OK to the wrong file.
Apply
- EX055 — Sort order. Why does config.yaml print before model.bin, and which line is OK?
Show marking criteria
Rubric: 3 =sortedputs config.yaml, model.bin, tokenizer.json; only the tokenizer line is OK; JSON insertion order is different;; 2 = alphabetical status order and the OK line;; 1 = names the OK file only;; 0 = follows JSON order.