Code of the Day
BeginnerAutomation Thinking

Lab: Automate a task

Write a complete script that reads a CSV of tasks, filters by status, counts by category, and prints a summary report.

Lab · optionalWorkflowBeginner30 min
Recommended first
By the end of this lesson you will be able to:
  • Read and parse an inline CSV using csv.DictReader
  • Filter rows by a field value
  • Aggregate counts by category using a dictionary
  • Print a formatted summary report

This lab puts the whole Automation Thinking module together. You will write a script that reads a list of tasks from an inline CSV, filters for completed tasks, counts them by category, and prints a clean summary report.

No new syntax here. The goal is to build the habit of combining the pieces you already know into something useful.

The scenario

Your team tracks tasks in a CSV file. Each row has a task name, a category, and a status (done or pending). Management wants a daily report: how many tasks are done per category?

Here is the data you are working with:

task,category,status
Write tests,engineering,done
Deploy to staging,engineering,done
Update docs,documentation,pending
Write changelog,documentation,done
Review PRs,engineering,done
Update README,documentation,done
Fix login bug,engineering,pending
Write user guide,documentation,pending

Checkpoint 1 — parse the CSV

Start by reading the data and printing every row as a dictionary:

Python — editable, runs in your browser

Each row is a dictionary like {'task': 'Write tests', 'category': 'engineering', 'status': 'done'}. That is the raw material for everything that follows.

Checkpoint 2 — filter for completed tasks

Add a condition to keep only rows where status == 'done':

Python — editable, runs in your browser

Checkpoint 3 — count by category

Use a dictionary to accumulate counts. For each completed task, increment the counter for its category:

Python — editable, runs in your browser

counts.get(cat, 0) returns the current count for cat, or 0 if the key does not exist yet. This is the idiomatic Python way to build a counter without a key-exists check.

Checkpoint 4 — the complete script

Put it all together into a main() function with clear output:

Python — editable, runs in your browser

Notice the structure: separate functions for loading, processing, and reporting. This makes each step easy to test and easy to swap out. If the data source changes from an inline string to a real file, you only touch load_tasks().

Extend it yourself

Once you have the script running, try these changes:

  1. Add a count of pending tasks per category alongside the done count.
  2. Add a --category filter so the report shows only one category.
  3. Change load_tasks() to accept a file path and read from a real CSV file on disk.

The third extension is the bridge to real automation: the script's logic stays the same; only the data source changes.

Finished reading? Mark it complete to track your progress.

On this page