Data Transformer
Part of the Logic & Flow section of Coddy's Python journey — lesson 78 of 78.
Challenge
HardCreate a function named transform_dataset that processes a list of student records for analysis.
Each record is a dictionary containing:
student_id: A unique identifier for the studentgrades: A list of numerical gradessubjects: A list of subjects the student is taking
Your function should:
- Calculate the average grade for each student
- Only include students who have all grades above 70 (qualified students) - you should use Python's
all()function to check this condition - Create a summary of the subjects taken by qualified students, counting how many qualified students take each subject
- Return a dictionary with two keys:
qualified_students: A dictionary mapping student IDs to their average grade (rounded to 2 decimal places)subject_summary: A dictionary mapping subjects to the count of qualified students taking that subject
Note: The all() function in Python returns True only if all elements in the iterable are true. For example, all(grade > 70 for grade in grades) will return True only if every grade is above 70.
Example Input:
[
{
"student_id": "S123",
"grades": [88, 92, 85],
"subjects": ["Math", "Science", "History"]
},
{
"student_id": "S124",
"grades": [65, 95, 80],
"subjects": ["Math", "Science", "English"]
},
{
"student_id": "S125",
"grades": [91, 89, 92],
"subjects": ["Math", "Physics", "History"]
}
]Example Output:
{
'qualified_students': {'S123': 88.33, 'S125': 90.67},
'subject_summary': {'Math': 2, 'Science': 1, 'History': 2, 'Physics': 1}
}Try it yourself
def transform_dataset(data):
# Your solution here
# Step 1: Calculate average grade for each student and filter qualified students
# (students with all grades above 70)
# Step 2: Create a summary of subjects taken by qualified students
# Step 3: Return the final dictionary with qualified_students and subject_summary
passAll lessons in Logic & Flow
1Variables Exploration
ConstantsMultiple Variable AssignmentsSwapping VariablesPlaceholder VariablesRound NumbersList Casting4Contact Book Application
Display MenuAdd Contact7Sets Part 2
Mathematical Operations Part 1Mathematical Operations Part 2Recap - Treasure HuntSubsets and SupersetsIterating Over SetsRecap - Tournament Tracker2Dictionaries Part 1
What is a Dictionary?Creating a DictionaryAccessing ValuesModifying DictionariesRecap - Recipe Manager5Advanced Decision Making
Ternary OperatorMembership ChecksIdentity ChecksIndentation ErrorsRecap - Vacation Filter8Student Records Manager
Project OverviewAdd Student11Advanced Functions
Returning Multiple ValuesLambda Functions Part 1Lambda Functions Part 2Recap Challenge - Lambda SortRecursive Functions Part 1Recursive Functions Part 2Recap - Sum Nested List14Higher-Order Functions
The Map FunctionThe Filter FunctionRecap - Email ValidatorRecap - Number Processor3Dictionaries Part 2
Dictionary MethodsNested DictionariesChecking for KeysLooping Through DictionariesRecap - Frequency Counter9Advanced Data Aggregation
Using SumFinding Minimum and MaximumSorting Data EfficientlyRecap - Dictionary Sorter