← Course Home
Module 13 · Tier 9

Group-Membership Flattener

Access-review spreadsheets always want one row per membership, not a nested blob per user. Ten labs on Module 11 — now starting from an exported file, not the in-memory fixture.

Lab 1

Today's Export

Write USERS out to "p1_export.json", then read it back with json.load(). Print len() of the loaded data.

12
Lab 2

Flatten With Nested Loops

Write flatten_memberships(users) — nested loops building one row per (user, group) membership, same fields as Module 11: email, lastName, department (guarded), group. Call it on the data you loaded in Lab 1. Print len().

15
Lab 3

Same Result, As a Comprehension

Write flatten_memberships_comp(users) — the same flattening as a single nested comprehension. Compare its result to Lab 2's with ==.

True
Lab 4

The Missing-Department Row

From your flattened rows, find Layla's (guard her missing department). Print the matching row(s).

[{'email': 'lhaddad@example.com', 'lastName': 'Haddad', 'department': 'Unknown', 'group': 'Contractors'}]
Lab 5

The Zero-Row Record

Confirm Dana has ZERO rows in the flattened output — she has no groups to flatten. Print the count.

0
Lab 6

Sort the Rows

Sort your flattened rows by lastName. Print the first row's last name, then the last row's.

Chen then Rivera
Lab 7

Preview the Top 3

Print the first 3 sorted rows as "LASTNAME -- GROUP (DEPARTMENT)".


Chen -- VPN-Users (Security)
Chen -- SecOps (Security)
Chen -- Admins (Security)
Lab 8

Write the Numbered Report

Write the sorted rows to "p8_report.txt", numbered with enumerate(..., start=1), same format as Lab 7 with a leading number.

file written, no crash
Lab 9

Confirm the Line Count

Read "p8_report.txt" back. Print how many lines it has.

15
Lab 10 · Capstone

The Full Flatten-and-Report Chain

Write USERS to "p10_export.json" → read it back → flatten → count distinct groups → sort → write a numbered report to "p10_report.txt" → print "N rows, M groups" → read the report back and print its line count.

15 rows, 6 groups then 15
Now go practice

Open problems/tier09_membership_flattener.py and do all 10 problems locally. Uses fixture.py -- type it in first from DAY1_01_FIXTURE.md if it's not already in this folder. Run python check.py in problems/ to grade everything.

Tier 9 complete

On to Tier 10

today's export → flattening with nested loops → the same flatten as a comprehension → the missing-department row → the zero-row record → sorting → previewing the top 3 → writing the numbered report → confirming the line count → the full flatten-and-report chain.

← Back to Module 13