Lazo Lab Sign up

App 2: To-Do List Manager / Build the to-do app

Lesson 9 of 10

Due dates and sorting

Add an optional due date to each task and sort the list so the soonest is first. Dates in YYYY-MM-DD format sort correctly as plain text.

Key points

  • Store dates as "2026-10-05"
  • sorted(tasks, key=...)
  • Tasks without dates go last
def by_due(t):
    return t.get("due") or "9999-12-31"

for t in sorted(tasks, key=by_due):
    print(t.get("due", "no date"), t["text"])

Your turn

Let users add a due date and show tasks sorted by date.

Watch a video on thisOpens YouTube search results for “Due dates and sorting” in a new tab

Quiz · +10 XP

Why do YYYY-MM-DD dates sort correctly as text?

Log in to save progress and earn XP.