Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def register(data):
- courses = {}
- students = {}
- result = ""
- while data != "end":
- course_name, student_name = data.split(" : ")
- if course_name not in courses:
- courses[course_name] = 1
- elif course_name in courses:
- courses[course_name] += 1
- students[student_name] = course_name
- data = input()
- ordered_courses = sorted(courses.items(), key=lambda x: (-x[1], x[0]))
- ordered_students = sorted(students.items())
- for course, count in ordered_courses:
- result += f"{course}: {count}\n"
- for student, subject in ordered_students:
- if subject == course:
- result += f"-- {student}\n"
- return result
- action = input()
- print(register(action))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement