An Airtable Interface may need to display records grouped by a selected field. Given a list of record objects, transform them into one summary object per group while preserving the order in which groups first appear.
Implement group_records(records, group_field, value_field, label_field).
For each group:
record[group_field] as the group name.record[value_field] to the group's numeric total.count.record[label_field] in first-seen order as labels.labels, preserve first appearance order.Each input record contains all requested fields. Values in label_field are strings, and values in value_field are integers or floats. Do not mutate the input records.
Input: records, a list of dictionaries, plus three strings naming fields. Return a list of dictionaries with keys group, total, count, and labels.
def group_records(records, group_field, value_field, label_field):