Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 01. Ranking . Dict more excercises NOT FINISHED ! 60/100 JUDGE !
- ********************************************************
- def is_course_valid(some_dict, some_course):
- if course_name in some_dict:
- return True
- return False
- def is_pass_valid(some_dict, current_course, current_pass):
- if some_dict[current_course][0] == current_pass:
- return True
- return False
- def clean_pass(some_list):
- for password in some_list:
- password = password.pop(1)
- return some_list
- def create_student_name_dict(matrix_list, students_names_dict):
- student_name_dict = {}
- for current_list in matrix_list:
- course = current_list[0]
- student_name = current_list[1]
- points = int(current_list[2])
- if student_name not in student_name_dict:
- student_name_dict[student_name] = [[course] + [points]]
- else:
- if student_name_dict[student_name][0][0] == course:
- if student_name_dict[student_name][0][1] < points:
- student_name_dict[student_name][0][1] = points
- else:
- student_name_dict[student_name] += [[course] + [points]]
- return student_name_dict
- def max_points(some_list, name):
- max_points = []
- for el in some_list:
- max_points.append(el[1])
- max_points = sum(max_points)
- return max_points, name
- data1 = input()
- all_students = {}
- all_passwords = {}
- all_courses = {}
- valid_information = []
- while not data1 == 'end of contests':
- data1 = data1.split(':')
- all_passwords[data1[0]] = [data1[1]]
- all_courses[data1[0]] = {}
- data1 = input()
- data2 = input()
- while not data2 == 'end of submissions':
- details = data2.split('=>')
- course_name = details[0]
- password = details[1]
- student_name = details[2]
- points = int(details[3])
- all_students[student_name] = {}
- if (is_course_valid(all_passwords, course_name)) and (is_pass_valid(all_passwords, course_name, password)):
- if student_name not in all_courses[course_name]:
- valid_information.append(details)
- data2 = input()
- clean_pass(valid_information)
- result = create_student_name_dict(valid_information, all_students)
- winner_name = ''
- winner_point = 0
- another_dict_try = {}
- for key, value in result.items():
- best_points, name = max_points(value, key)
- value = sorted(value, key=lambda x: x[0])
- if best_points > winner_point:
- winner_point = best_points
- winner_name = name
- another_dict_try[key] = value
- print(f'Best candidate is {winner_name} with total {winner_point} points.')
- print('Ranking:')
- another_dict_try = sorted(result.items(), key=lambda y: y[0])
- for name in another_dict_try:
- print(name[0])
- sorted_grade = sorted(name[1], key=lambda x: x[1], reverse=True)
- for grade in sorted_grade:
- print(f'# {grade[0]} -> {grade[1]}')
Add Comment
Please, Sign In to add comment