project working for hard coded book
This commit is contained in:
26
stats.py
Normal file
26
stats.py
Normal file
@@ -0,0 +1,26 @@
|
||||
def count_words(text):
|
||||
return len(text.split())
|
||||
|
||||
def count_characters(text):
|
||||
t = dict()
|
||||
text = text.lower()
|
||||
for c in text:
|
||||
if c in t.keys():
|
||||
t[c] += 1
|
||||
else:
|
||||
t.update({c:1})
|
||||
|
||||
return t
|
||||
|
||||
|
||||
def sort_on(items):
|
||||
return items["num"]
|
||||
|
||||
def sort_by_count(data):
|
||||
l = []
|
||||
|
||||
for c in data:
|
||||
l.append({"char":c, "num":data[c]})
|
||||
|
||||
l.sort(reverse=True, key=sort_on)
|
||||
return l
|
||||
Reference in New Issue
Block a user