Advertisement
bl00dt3ars

07. Courses

Aug 13th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. collected_data = {}
  2. input_data = input()
  3.  
  4. while not input_data == "end":
  5.     course, student = input_data.split(" : ")
  6.     if course not in collected_data:
  7.         collected_data[course] = []
  8.     collected_data[course].append(student)
  9.     input_data = input()
  10.  
  11. collected_data = sorted(collected_data.items(), key=lambda kvp: -len(kvp[1]))
  12.  
  13. for courses, students in collected_data:
  14.     print(f"{courses}: {len(students)}")
  15.     students = sorted(students)
  16.     for current_student in students:
  17.         print(f"-- {current_student}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement