SHARE
TWEET

Untitled

a guest Mar 26th, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. k = int(input('Введите число призовых мест: '))
  2. file_name = input('Имя файла: ') + '.txt'
  3. protocol = open(file_name, 'r')
  4. file_lines = protocol.readlines()
  5. dict = {} # name : [points, step, logo_exist]
  6. step = 1
  7. print('Первые десять записей в протоколе: ')
  8. for line in file_lines:
  9.     player_name = line[line.find(' ')+1:-1]
  10.     player_points = int(line[:line.find(' ')])
  11.     if step<=10:
  12.         print(player_points, player_name)
  13.     if player_name not in dict:
  14.         dict[player_name] = []
  15.         dict[player_name].append(player_points)
  16.         dict[player_name].append(step)
  17.     elif player_points > dict[player_name][0]:
  18.         dict[player_name][1] = step
  19.         dict[player_name][0] = player_points
  20.     step += 1
  21.  
  22. protocol_items = list(dict.items())
  23. protocol_items = sorted(protocol_items, key=lambda point: (point[1][0], -point[1][1]), reverse=True)
  24. print()
  25. print('Призовые места:')
  26. for i in range(0,k):
  27.     print(i+1,'.',end= ' ')
  28.     print(protocol_items[i][0], end = ' ')
  29.     print('(' + str(protocol_items[i][1][0]) + ')')
  30. protocol.close()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top