update
This commit is contained in:
26
stats.py
Normal file
26
stats.py
Normal file
@@ -0,0 +1,26 @@
|
||||
def get_num_words(text):
|
||||
words = text.split()
|
||||
return len(words)
|
||||
|
||||
|
||||
def get_chars_dict(text):
|
||||
chars = {}
|
||||
for c in text:
|
||||
lowered = c.lower()
|
||||
if lowered in chars:
|
||||
chars[lowered] += 1
|
||||
else:
|
||||
chars[lowered] = 1
|
||||
return chars
|
||||
|
||||
|
||||
def sort_on(d):
|
||||
return d["num"]
|
||||
|
||||
|
||||
def chars_dict_to_sorted_list(num_chars_dict):
|
||||
sorted_list = []
|
||||
for ch in num_chars_dict:
|
||||
sorted_list.append({"char": ch, "num": num_chars_dict[ch]})
|
||||
sorted_list.sort(reverse=True, key=sort_on)
|
||||
return sorted_list
|
||||
Reference in New Issue
Block a user