Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I can get this far (below), but all I have now is two lists with the names and the grades. I know im approaching this
I can get this far (below), but all I have now is two lists with the names and the grades. I know im approaching this wrong, which way should I approach? Cheers (python)
Write a function called create_grade_dictionary (students) that takes a list of student-tuples as a parameter and returns a dictionary that maps from grade to a list of students who obtained that grade. The student list in each grade-item in the dictionary should be sorted in ascending order (smallest to largest/A-Z) For example: Test Result students = [('Angus', 'A+'), ('Peter', 'C+'), ('Fred', 'C+'), ('Mary','A'), ('Liu','C+')] A ['Mary'] grades = create_grade_dictionary (students) A+ ['Angus'] for k in sorted(grades): C+ ['Fred', 'Liu', 'Peter'] print(k, grades[k]) L wewew.py - C:/Users/willi/AppData/Local/Programs/Python/Python37-32/wewew.py (3.7.4) File Edit Format Run Options Window Help def create grade dictionary (students): dict1 = {} grades = [] names = [] for ele in students: names.append(ele[0]). if ele[1] not in grades: grades.append(ele[1]) students = [('Angus', 'A+'), ('Peter', 'C+'), ('Fred', 'C+'), ('Mary', 'A'), ('Liu', 'C+')] grades = create grade dictionary (students), for k in sorted (grades): print(k, grades[k])
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started