a description of your changes here
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
books/
|
||||
23
main.py
Normal file
23
main.py
Normal 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 ---')
|
||||
Reference in New Issue
Block a user