Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import Counter
- import sys
- uniq_chars = Counter()
- if len(sys.argv) >= 2:
- text = open(sys.argv[1], 'r+')
- else:
- while True:
- f = input('Введите пожалуйста имя файла: ')
- try:
- text = open(f, 'r+')
- break
- except FileNotFoundError:
- print('Вы не ввели имя файла, или такого файла не существует')
- continue
- for x in text:
- uniq_chars += Counter(x.strip().lower())
- text.close()
- uniq_words = uniq_chars.most_common(2)
- if uniq_words [0][0] == ' ':
- print("In this file, the most common letter is ", uniq_words[1][0],
- "it repeated ", uniq_words[1][1], "times")
- else:
- print('In this file, the most common letter is ', uniq_words[0][0],
- 'it repeated ', uniq_words[0][1], 'times')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement