Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1.  
  2. from collections import Counter
  3. import sys
  4.  
  5.  
  6. uniq_chars = Counter()
  7. if len(sys.argv) >= 2:
  8. text = open(sys.argv[1], 'r+')
  9. else:
  10. while True:
  11. f = input('Введите пожалуйста имя файла: ')
  12. try:
  13. text = open(f, 'r+')
  14. break
  15. except FileNotFoundError:
  16. print('Вы не ввели имя файла, или такого файла не существует')
  17. continue
  18.  
  19.  
  20. for x in text:
  21. uniq_chars += Counter(x.strip().lower())
  22.  
  23. text.close()
  24. uniq_words = uniq_chars.most_common(2)
  25.  
  26. if uniq_words [0][0] == ' ':
  27. print("In this file, the most common letter is ", uniq_words[1][0],
  28. "it repeated ", uniq_words[1][1], "times")
  29. else:
  30. print('In this file, the most common letter is ', uniq_words[0][0],
  31. 'it repeated ', uniq_words[0][1], 'times')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement