SHARE
TWEET

Untitled

a guest Mar 26th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from operator import itemgetter
  2.  
  3. score_table = {}
  4.  
  5. k = int(input('Количество призов: '))
  6.  
  7. filename = "text.txt"
  8. #filename = input('Имя файла: ')
  9.  
  10. f = open(filename, "r")
  11.  
  12. lines = 0
  13. for line in f:
  14.     lines += 1
  15.     s = line.split()
  16.     if s[1] in score_table:
  17.         if int(s[0]) > score_table[s[1]]:
  18.             score_table[s[1]] = int(s[0])
  19.     else:
  20.         score_table[s[1]] = int(s[0])
  21.  
  22. record_table = list(score_table.items())
  23. record_table = sorted(record_table, key=lambda tup: tup[1], reverse=True)
  24.  
  25. print('Количество строк протокола: ', lines)
  26. print('Первые десять записей')
  27.  
  28. kg = 0
  29. for name in score_table:
  30.     if kg <= 10:
  31.         print(name, score_table[name])
  32.     kg += 1
  33.  
  34. print('Победители')
  35.  
  36. for i in range(k):
  37.     score = record_table[i]
  38.     print(str(i+1) + '.', score[0], score[1])
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