How would you implement a function to aggregate data efficiently in Python?
Implement aggregate_data(records, group_by, sum_fields). records is a list of dictionaries, group_by is the grouping-field name, and sum_fields lists numeric fields to sum. Return a list of dictionaries ordered by each group’s first appearance. Each output dictionary contains the grouping field and the requested sums. Assume every record contains all requested fields and grouping values are hashable.
def aggregate_data(records, group_by, sum_fields):