Advertisement
pavlinpetkov420

06.Courses

Nov 16th, 2020
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. def process_data():
  2.     courses_n_students = {}
  3.  
  4.     while True:
  5.         command = input()
  6.         if command == "end":
  7.             return courses_n_students
  8.         course, student = command.split(" : ")
  9.         if course not in courses_n_students.keys():
  10.             courses_n_students[course] = []
  11.         courses_n_students[course].append(student)
  12.  
  13.  
  14. def print_data(courses_data):
  15.     ordered_dictionary = dict(sorted(courses_data.items(), key=lambda x: x[0]))
  16.     for course_name in ordered_dictionary.keys():
  17.         people_on_course = len(ordered_dictionary[course_name])
  18.         print(f"{course_name}: {people_on_course}")
  19.         for student in ordered_dictionary[course_name]:
  20.             print(f"-- {student}")
  21.  
  22.  
  23. courses = process_data()
  24. print_data(courses)
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement