pythonintermediate15 minutes

Build a Task Progress Tracker with Status Summary

Create a Python function to track the progress of multiple tasks with varying statuses and provide a summary of counts per status.

Challenge prompt

You are given a list of task dictionaries where each task has at least a 'name' and a 'status'. Status can be 'Pending', 'In Progress', or 'Completed'. Write a function `track_task_progress(tasks)` that returns a summary dictionary containing the count of tasks for each status and a list of all tasks grouped by their status. The output dictionary should have statuses as keys, each mapping to a dictionary with two keys: 'count' for the number of tasks, and 'tasks', a list of task names having that status.

Guidance

  • Iterate through the list of tasks, grouping them by their status.
  • Count the number of tasks for each status and collect their names.
  • Return a dictionary structured as {status: {'count': int, 'tasks': [list of task names]}, ...}.

Hints

  • Consider using a dictionary to accumulate results as you iterate.
  • Use dict.setdefault() or collections.defaultdict for easier grouping.
  • Ensure to handle cases when no tasks exist for a particular status.

Starter code

def track_task_progress(tasks):
    # Your code here
    pass

Expected output

For input: [ {'name': 'Task 1', 'status': 'Pending'}, {'name': 'Task 2', 'status': 'In Progress'}, {'name': 'Task 3', 'status': 'Pending'}, {'name': 'Task 4', 'status': 'Completed'} ] Output: { 'Pending': {'count': 2, 'tasks': ['Task 1', 'Task 3']}, 'In Progress': {'count': 1, 'tasks': ['Task 2']}, 'Completed': {'count': 1, 'tasks': ['Task 4']} }

Core concepts

dictionarieslist iterationgrouping dataconditional logic

Challenge a Friend

Send this duel to someone else and see if they can solve it.