Codington
0 of 6 problems solved • 0%

Exercise prompt

Publish a Weather Report

Your weather station exports a UTF-8 CSV file. A dashboard needs a JSON object keyed by date. This is the last step from raw file to daily report.

Example

Group records by day, then encode one result for each group.

import json visits = [("Mon", 2), ("Tue", 1), ("Mon", 4)] totals = {} for day, count in visits: totals[day] = totals.get(day, 0) + count print(json.dumps(totals, sort_keys=True)) # {"Mon": 6, "Tue": 1}

Group observations before serializing. A weather group needs extrema and a count, and some input rows will never enter a group.

Your task

Implement weather_report(path). Read the date and temperature columns by name. Dates are valid ISO date strings. Skip nonnumeric temperatures and values outside -50 to 60 inclusive. For each date with valid readings, produce low, high, and count. Return JSON text. Field order and whitespace are up to you.

# Sample file: # date,temperature # 2026-03-01,3 # 2026-03-01,ERR # 2026-03-01,-1 # Decoded result: {"2026-03-01": {"low": -1, "high": 3, "count": 2}}