Lesson 14: Hashmaps
Post date: Feb 1, 2018 3:50:24 PM
import word_dict
def wordlength(x):
searchspace = []
for w in word_dict.db:
if len(w) == x:
searchspace.append(w)
return searchspace
def lengthstat(searchspace):
maxlength = 0
for w in searchspace:
if len(w) > maxlength:
maxlength = len(w)
lstat = {}
for x in range(0,maxlength + 1):
lstat[x] = 0
for w in searchspace:
lstat[len(w)] += 1
return lstat
def letterstat(searchspace):
abc = "abcdefghijklmnopqrstuvwxyz"
lstat = {}
for l in abc:
lstat[l] = 0
for w in searchspace:
w = w.lower()
for l in w:
lstat[l] += 1
return lstat
space = wordlength (16)
print(space)
print(lengthstat(word_dict.db))
lstat = letterstat(word_dict.db)
for l in "abcdefghijklmnopqrstuvwxyz":
print(l, "=", lstat[l])