Lesson 14: Searching

posted Feb 2, 2018, 8:03 AM by Attila Lengyel
import word_dict

def wordlength(space, length):
  searchspace = []
  for w in space:
    if len(w) == length:
      searchspace.append(w)
  return searchspace

def eliminateMissed(space, missedletters):
  searchspace = []
  for w in space:
    w = w.lower()
    add = True
    for l in w:
      if missedletters.find(l) > -1:
        add = False
    if add:
      searchspace.append(w)
  return searchspace
  
print(eliminateMissed(word_dict.db, "aeiou"))

result = wordlength(word_dict.db, 6)
print(result, len(result))

for x in range (0,20):
  result = wordlength(word_dict.db, x)
  print(x, len(result))

result = wordlength(word_dict.db, 7)
result = eliminateMissed(result, "tbpthklswqfmvcxz")
print(result)

Comments