Overview
By the end of the last part, your study log was persistent. Sessions you logged on Monday were still there on Tuesday. The program had learned to remember.
What it has not yet learned is to make use of what it remembers.
If you have been using the log between parts, you now have a real file with real sessions in it. At the end of each run, the program prints a short summary — total minutes, number of sessions, and longest single session. But the summary has not kept up with the data. It does not break time down by subject. It does not say which day was heaviest. It does not know whether you have studied two days in a row or twenty. The data is sitting in the file, and most of it is being ignored.
In this part, you will learn to compute small, useful facts from large piles of records — the operations that turn a list of sessions into “you have studied 14 hours of math this month” or “you are on a five-day streak”.
The structure of this part is as follows:
- Applying Summary Patterns to Rows reuses counting, totalling, and averaging on session rows, with the unpacking-in-the-loop fluency move.
- Summaries by Category writes the per-subject summary with lists alone.
- Working With Dates and Date Windows extends
date.today()into parsing, comparison, subtraction, and inclusive time ranges. - Sorting and Ranked Summaries covers
sorted, key functions, and[:n]slicing. - Summaries by Day applies the category-summary pattern to dates.
- Streaks of Consecutive Days demonstrates how to compute streaks.
- A Compact Form: List Comprehensions introduces the one-line form for a few small list-building loops.
- Comparing Reasonable Approaches is the AI-collaboration chapter.
- Adding an Opening Dashboard to Your Study Log is the project checkpoint.
Finally, the recap and feedback chapter summarizes what was covered and asks for feedback.
Summaries and Empty-Data Results
In this part, you’ll write plenty of summary functions. Each one you write will have a small contract — a specification of what it returns on normal data, and what it returns on empty data. The summary-contract table below makes these commitments explicit:
| Question | Normal result | Empty-data result |
|---|---|---|
| How many items match? | Integer count | 0 |
| How many minutes match? | Integer total | 0 |
| What is the average? | Number | None |
| What is the longest session? | Number or row | None |
| What are the totals by subject? | List of summary rows | [] |
| What is the heaviest day? | [date_string, minutes] | None |
| What is the current or longest streak? | Integer number of days | 0 |
The pattern is small: counts and totals return zero on empty input; averages and “best of” answers return None; collections of summaries return empty collections. Writing a summary function starts with deciding which question it answers, and then committing to the right empty-data result for that question.
Recommended Order of Work
- read the regular chapters in order, completing exercises as you go,
- complete the project checkpoint in Adding an Opening Dashboard to Your Study Log,
- and finish with the recap and feedback.
The new mechanical material in this part is bounded — dates, sorting, and the small list-comprehension form. The harder work is in the compositions you write on top of them: per-category summaries, time-window filters, daily totals, streaks.