-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
31 lines (22 loc) · 675 Bytes
/
stats.py
File metadata and controls
31 lines (22 loc) · 675 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
def sort_characters(characterDict):
charList = []
for key, value in characterDict.items():
newDict = {"char": key, "num": value}
charList.append(newDict)
def sort_on(items):
return items["num"]
charList.sort(reverse = True, key = sort_on)
return charList
def get_num_words(text):
words = text.split()
return len(words)
def count_characters(text):
characterDict = {}
count = 0
lowerCaseText = text.lower()
for character in lowerCaseText:
if character in characterDict:
characterDict[character] += 1
else:
characterDict[character] = 1
return characterDict