Fix JSON object suitable for automating the programming task testing…
- User
Assistant: User: Fix JSON object suitable for automating the programming task testing platform, strictly in the following format:
"Target Task": { "Title": "Transform and Aggregate Data", "Task Description": "Given a list of dictionaries, each representing a record with 'id', 'value', and 'category' keys, transform the data by aggregating the sum of 'value' for each unique 'category'. Return a dictionary where keys are categories and values are the aggregated sums.", "Function Signature": "def aggregate_data(records: list) -> dict:", "Solve": " from collections import defaultdict
def aggregate_data(records: list) -> dict: category_sums = defaultdict(int) for record in records: category = record['category'] value = record['value'] category_sums[category] += value return dict(category_sums)", "Input": ""records" is a list of dictionaries. Each dictionary contains three keys: "id" (int), "value" (int or float), and "category" (str).", "Output": ""output_dict" is a dictionary where each key is a unique category from input records, and its corresponding value is the sum of all values associated with that category.", "Examples": [ { "input": "[{'id': 1, 'value': 10, 'category': 'A'}, {'id': 2, 'value': -5, 'category': 'B'}, {'id':3,'value':7,'category':'A'}]", "output": "{'A':17,'B':-5}" }, { "input": "[{'id':4,'value':20.5,'category':'C'},{'id':5,'value'=>15.0,'category'=>'C'}]", "output": "{'C'=>35.5}" } ] }Ensure that the JSON follows this exact structure and does not include any additional text or variations. The task should be complex and unique, avoiding direct copying from common platforms like LeetCode or similar sources.
Assistant:
- Assistant
{ "Target Task": { "Title": "Transform and Aggregate Data", "Task Description": "Given a list of dictionaries, each representing a record with 'id', 'value', and 'category' keys, transform the data by aggregating the sum of 'value' for each unique 'category'. Return a dictionary where keys are categories and values are the aggregated sums.", "Function Signature": "def aggregate_data(records: list) -> dict:", "Solve": " from collections import defaultdict def aggregate_data(records: list) -> dict: category_sums = defaultdict(int) for record in records: category = record['category'] value = record['value'] category_sums[category] += value return dict(category_sums)", "Input": "\"records\" is a list of dictionaries. Each dictionary contains three keys: \"id\" (int), \"value\" (int or float), and \"category\" (str).", "Output": "\"output_dict\" is a dictionary where each key is a unique category from input records, and its corresponding value is the sum of all values associated with that category.", "Examples": [ { "input": "[{'id': 1, 'value': 10, 'category': 'A'}, {'id': 2, 'value': -5, 'category': 'B'}, {'id': 3, 'value': 7, 'category': 'A'}]", "output": "{'A': 17, 'B': -5}" }, { "input": "[{'id': 4, 'value': 20.5, 'category': 'C'}, {'id': 5, 'value': 15.0, 'category': 'C'}]", "output": "{'C': 35.5}" } ] } }