Your question is Aggregate Data From Dictionaries. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Insight Data Science receives event records as a list of dictionaries. Write a function that groups the records by one dictionary field and calculates both the number of records and the sum of a numeric field for each group.
Return one dictionary per group in the order each group first appears in the input. Each result dictionary must contain the grouping field, count, and total.
Implement aggregate_records(records, group_key, metric_key).
records is a list of dictionaries.group_key and metric_key are strings naming fields present in every record.records[i][metric_key] is an integer or floating-point number.group_key mapped to a group value, count mapped to the number of records in that group, and total mapped to the sum of the metric values.records.def aggregate_records(records, group_key, metric_key):