/
rnekrasov
/
Python
Обзор
Документация
Войти
/
rnekrasov
/
Python
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
CountMillionCharacters-Variations/variation1.py
32 строки
737 B
slowy07
refactor: clean code
30 янв 2022, 04:33
30 янв 2022, 04:33
f0af0c4
Код
Авторство
О чём код?
try: input = raw_input except NameError: pass def count_chars(filename): count = {} with open(filename) as info: # inputFile Replaced with filename readfile = info.read() for character in readfile.upper(): count[character] = count.get(character, 0) + 1 return count def main(): is_exist = True # Try to open file if exist else raise exception and try again while is_exist: try: inputFile = input("File Name / (0)exit : ").strip() if inputFile == "0": break print(count_chars(inputFile)) except FileNotFoundError: print("File not found...Try again!") if __name__ == "__main__": main()