a description of your changes here

This commit is contained in:
2025-01-19 18:11:55 +02:00
parent e2229b9d3d
commit ad5c97a011
2 changed files with 24 additions and 0 deletions

23
main.py Normal file
View File

@@ -0,0 +1,23 @@
chars = {}
filename = 'books/frankenstein.txt'
with open(filename) as f:
print(f"--- Begin report of {filename} ---")
file_contents = f.read()
words = len(file_contents.split())
print(f"{words} words found in the document\n")
for char in file_contents:
lower = char.lower()
if 'a' <= lower and lower >= '<':
if lower not in chars:
chars[lower] = 0
chars[lower] += 1
sorted_dict = dict(sorted(chars.items(), key=lambda item: item[1], reverse=True))
for char in sorted_dict:
print(f"The '{char}' character was found {chars[char]} times")
print('--- End report ---')