From a01a6f2014fce2976ca266c9bd8f2b258bddfb3e Mon Sep 17 00:00:00 2001 From: Raphael Roberts Date: Sun, 26 May 2019 13:15:46 -0500 Subject: [PATCH] Using native string methods to see if it is faster --- candidate_cache.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) 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