Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. inFile = open('input.txt', 'r', encoding='utf8')
  2. outFile = open('output.txt', 'w', encoding='utf8')
  3.  
  4. string = inFile.readlines()
  5. c = {}
  6. countVoices = 0
  7. for d in string:
  8. p = d.strip()
  9. c[p] = c.get(p, 0) + 1
  10. countVoices += 1
  11.  
  12. c = sorted(c.items(), key=lambda x: x[1], reverse=True)
  13. percent = c[0][1] / countVoices * 100
  14. if percent > 50:
  15. print(c[0][0], file=outFile)
  16. else:
  17. for name, _ in c[:2]:
  18. print(name, file=outFile)
  19. inFile.close()
  20. outFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement