-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
38 lines (27 loc) · 754 Bytes
/
stats.py
File metadata and controls
38 lines (27 loc) · 754 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
36
def get_num_words(book):
words = []
words = book.split()
#print(len(words))
word_count = len(words)
return word_count
def get_char_count(book):
book = book.lower()
char_list = list(book)
char_dict = {}
#print(char_list)
for char in char_list:
if char in char_dict:
char_dict[char] += 1
else:
char_dict[char] = 1
#print(char_dict)
# print(len(char_list))
return char_dict
def get_sorted_data(raw_chars_dict):
sorted_list = []
for key, value in raw_chars_dict.items():
sorted_list.append({"char": key, "num": value})
sorted_list.sort(reverse=True, key=sort_on)
return sorted_list
def sort_on(dict):
return dict["num"]