-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
36 lines (27 loc) · 771 Bytes
/
Copy pathstats.py
File metadata and controls
36 lines (27 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# BOOKBOT STATISTICS FILE
def get_word_count(text):
text_str = f"{text}"
book_words = len(text_str.split())
return book_words
def character_count(text):
chars = {}
text_str = f"{text}"
lowercase_text = text_str.lower()
for char in lowercase_text:
if char.isalpha():
for ch in char:
if ch in chars:
chars[char] += 1
else:
chars[char] = 1
return chars
def sort_on(dict):
return dict["num"]
def sort_dict(dict):
dict_list = []
for char in dict:
count = dict[char]
new_dict = {"char": char, "num": count}
dict_list.append(new_dict)
dict_list.sort(reverse=True, key=sort_on)
return dict_list