Structuring Your Data

Overview


By the end of the last part, your study log could answer real questions. It totalled your minutes by subject, found your heaviest day, tracked your streak. But look closely at the code that does this work and you will keep seeing the same pattern:

for subject, minutes, day in sessions:
if subject == wanted_subject:
total += minutes

The names subject, minutes, day only exist because the loop header unpacks them. The data underneath is still a plain list, and the only thing that makes minutes mean “minutes” is that it happens to sit in position 1. Every function that touches a session has to know that subject is row[0], minutes is row[1], and the date is row[2]. That knowledge lives in your head, not in the data.

In this part, you will learn ways to put that knowledge into the data itself. You will give your data structure, so that the meaning of each field is clear from the way it is stored. You will learn to use dictionaries for named lookup, JSON for storing named data, and classes for defining your own record types.

The structure of this part falls into three groups of chapters, following the three new tools:

Dictionaries:

Records and JSON:

Classes:

The three groups are followed by the AI-collaboration chapter and project checkpoint:

Finally, the recap and feedback chapter summarizes what was covered and asks for feedback.

  1. read the regular chapters in order, running the examples as you go,
  2. complete the project checkpoint in Refactoring the Study Log with Classes,
  3. and finish with the recap and feedback.

The three tools build on each other, so the order matters more than usual this part. Dictionaries make records natural; records make JSON natural; the limitations of loose dictionaries make classes natural. Read in sequence and each tool will feel like the answer to a question the previous one raised.