-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
37 lines (29 loc) · 898 Bytes
/
stats.py
File metadata and controls
37 lines (29 loc) · 898 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
def num_words(text):
words = text.split()
return len(words)
def count_unique(text):
# list_words=[]
lowerCase=text.lower()
# words = lowerCase.split()
# list_words.append(lowerCase)
# set_words = set(list_words)
letter_count = {}
for i in lowerCase:
if i in letter_count:
letter_count[i]+=1
else:
letter_count[i]=1
return letter_count
def sort_on(item):
return item["num"]
def sort_letters(count_letters):
letter_list = []
for letter, count in count_letters.items():
if letter.isalpha(): # skip non-alphabetical characters
letter_list.append({
"char": letter,
"num": count
})
#letter_list.append({"letter": letter, "num": count})
letter_list.sort(reverse=True, key=sort_on)
return letter_list