Syllabus Lesson 106 of 141 · Past the tenth idea
Past the tenth idea

Prototype one: what changed while you were away

Why it matters An idea is cheap until it meets a test. A small honest prototype shows whether the unusual idea holds up, and it often shows the hard part nobody saw.

The card "the user comes back after a year away" gave the to-do app a feature that is not in the top ten: when you open a shared list, it first shows what changed since your last visit. Not every edit: the net change. If a task's owner went from Ana to Ben and back to Ana, nothing changed for you.

The edit log is long and lives on the server; every entry fetched costs. Your last visit was recent, so only the end of the log matters.

The data

log = [(1, "t1", "status", "todo"), (2, "t2", "owner", "ana"), (5, "t1", "status", "doing"),
       (6, "t2", "owner", "ben"), (7, "t2", "owner", "ana"), (8, "t3", "title", "New"), (9, "t1", "status", "done")]
snapshot = {("t1", "status"): "todo", ("t2", "owner"): "ana"}   # what you saw at time 4
changes_since(Tape(log), snapshot, 4)
# {("t1", "status"): ("todo", "done"), ("t3", "title"): (None, "New")}
Your turn

Write changes_since(log, snapshot, since). log is a Tape of (t, item, field, value) edits sorted by t (whole numbers, increasing). snapshot maps (item, field) to the value the user saw at time since. Return a dict from (item, field) to (old, new) for every field edited after since whose latest value differs from the snapshot; old is the snapshot value, or None if the field is new. An edit that is later put back, or that sets the same value, is not a change. Budget: the log has 50,300 edits and about 300 are after since; read at most 3,000 entries. len() is free.

Spotted a problem in this lesson? Report it · Ask about this lesson

This exercise opens soon

Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.