elena1234

Student Academy - sorting by average value ( in Python )

Jan 28th, 2022 (edited)
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. from statistics import mean
  2.  
  3. university = {}
  4. number_row = int(input())
  5.  
  6. for i in range(number_row):
  7.     student = input()
  8.     grade = float(input())
  9.    
  10.     if student not in university:
  11.         university[student] = []
  12.         university[student].append(grade)
  13.     else:
  14.         university[student].append(grade)
  15.  
  16. sorted_dict = dict(sorted(university.items(), key = lambda x:  -mean(x[1])))
  17. for student, grades in sorted_dict.items():
  18.     if mean(grades) >= 4.50:
  19.         average_grade = mean(grades)
  20.         print(f"{student} -> {average_grade:.2f}")
Add Comment
Please, Sign In to add comment