Advertisement
GeorgiLukanov87

02. Judge Functions Dictionaries - More Exercises 100/100

Jul 18th, 2022
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # 02. Judge Dictionaries - More Exercises 100/100
  2. # https://judge.softuni.org/Contests/Practice/Index/1738#1
  3.  
  4. def calculate_individual_points_func():
  5.     max_points = {}
  6.     for current_name, current_points in my_dict.items():
  7.         for key, value in current_points.items():
  8.             if key not in max_points:
  9.                 max_points[key] = value
  10.             else:
  11.                 max_points[key] += value
  12.     counter = 0
  13.     print('Individual standings:')
  14.     for current_name, score in sorted(max_points.items(), key=lambda kvp: (-kvp[1], kvp[0])):
  15.         counter += 1
  16.         print(f"{counter}. {current_name} -> {score}")
  17.  
  18.  
  19. data = input()
  20. my_dict = {}
  21. while not data == 'no more time':
  22.     details = data.split(" -> ")
  23.     name = details[0]
  24.     contest = details[1]
  25.     points = int(details[2])
  26.     if contest not in my_dict.keys():
  27.         my_dict[contest] = {name: points}
  28.     elif contest in my_dict.keys():
  29.         if name in my_dict[contest]:
  30.             old_points = my_dict[contest][name]
  31.             if points > old_points:
  32.                 my_dict[contest].update({name: points})
  33.         else:
  34.             my_dict[contest].update({name: points})
  35.  
  36.     data = input()
  37.  
  38. for k, v in my_dict.items():
  39.     print(f"{k}: {len(v.keys())} participants")
  40.     student_counter = 0
  41.     for name, point in sorted(v.items(), key=lambda kvp: (-kvp[1], kvp[0])):
  42.         student_counter += 1
  43.         print(f"{student_counter}. {name} <::> {point}")
  44.  
  45. calculate_individual_points_func()
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement