diff --git a/candidate_cache.py b/candidate_cache.py index 51e7442..2d5d9a9 100644 --- a/candidate_cache.py +++ b/candidate_cache.py @@ -7,17 +7,11 @@ def make_key(dictionary_name, letters): def candidates(letters, dictionary: Dictionary, min=2, permutations=None): - letter_counter = Counter(letters) + letters = "".join(letters) 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) return possibilities