Browse Source

Using native string methods to see if it is faster

dictionary_check
Raphael Roberts 7 years ago
parent
commit
a01a6f2014
  1. 14
      candidate_cache.py

14
candidate_cache.py

@ -7,17 +7,11 @@ def make_key(dictionary_name, letters):
def candidates(letters, dictionary: Dictionary, min=2, permutations=None): def candidates(letters, dictionary: Dictionary, min=2, permutations=None):
letter_counter = Counter(letters)
letters = "".join(letters)
possibilities = [] possibilities = []
for word in dictionary.word_frequency.keys():
word_counter = Counter(word)
try:
add = all(
word_counter[key] <= letter_counter[key] for key in word_counter.keys()
)
except KeyError:
add = False
if add:
for word in filter(lambda word: len(word) > min, dictionary.word_frequency.keys()):
letter_set = set(word)
if all(word.count(letter) < letters.count(letter) for letter in letter_set):
possibilities.append(word) possibilities.append(word)
return possibilities return possibilities

Loading…
Cancel
Save