fork download
  1. #Дан текст. Выведите слово, которое в этом тексте встречается чаще всего. Если таких слов несколько, выведите #то, которое меньше в лексикографическом порядке.
  2. from collections import Counter
  3.  
  4. m = []
  5. file = open("input.txt")
  6. k = "zzzzzzzzzzzzzzzz"
  7. for line in file:
  8. freqs = Counter(line.split())
  9. max_values = max(freqs.values())
  10. min_key = min(freqs.keys())
  11. if k > min_key:
  12. k = min_key
  13.  
  14. if max_values == 1:
  15. print(k)
  16. else:
  17. for word, count in freqs.items():
  18. if count > 1:
  19. m.append(word)
  20. (sorted(m))
  21. print(m[1])
  22.  
Runtime error #stdin #stdout #stderr 0.02s 28384KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 5, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'input.txt'