Shaping data
Records in, structure out. Grouping, merging, and the aliasing bugs that make a copy quietly not a copy.
—Exercises
12 exercises
Tally records by a field
dict.get with a default, accumulating
~15 min
Index records by a unique field
dict as an index, detecting duplicates
~15 min
Pull one field out of every record
comprehension over records, a default that means absent
~12 min
New names, same places
rebuilding a dict, keeping order
~16 min
The best few, without disturbing the rest
sort stability, reverse= versus reversing
~18 min
Reach into nested data safely
walking nested dicts, defaults over exceptions
~20 min
Group records by a field
dict.setdefault, grouping
~20 min
Turning a lookup around
the inverse of a function, silent collisions
~20 min
Sorting by several fields at once
stable sort, successive passes
~24 min
What changed between these two
set algebra on keys, three-part results
~25 min
Nested data, one level deep
recursion over a tree, path building
~25 min
Merge configuration, deeply
recursion, deep vs shallow copy
~30 min