Lesson 16: Automated letter guess

Post date: Feb 15, 2018 3:38:25 PM

import word_dict

def wordlength(searchspace, length):

space = []

for w in searchspace:

if len(w) == length:

space.append(w)

return space

def patternmatch(searchspace, pattern):

space = []

for w in searchspace:

add = True

for x in range(0, len(w)):

if pattern[x] != "_" and pattern[x] != w[x]:

add = False

break

if add: space.append(w)

return space

def eliminatemissed(searchspace, missedletters):

space = []

for w in searchspace:

add = True

for l in w:

if missedletters.find(l) > -1:

add = False

break

if add: space.append(w)

return space

def letterstat(searchspace):

abc = "abcdefghijklmnopqrstuvwxyz"

lstat = {}

for l in abc:

lstat[l] = 0

for w in searchspace:

letters = ""

w = w.lower()

for l in w:

if letters.find(l) == -1:

letters += l

for l in letters:

lstat[l] += 1

return lstat

space = wordlength(word_dict.db, 4)

space = patternmatch(space, "_ee_")

space = eliminatemissed(space,"ns")

print (space)

space = letterstat(space)

print (space)