diff --git a/extension.py b/extension.py index e818ec7..ae99b8f 100644 --- a/extension.py +++ b/extension.py @@ -2,7 +2,7 @@ from collections import Counter import pickle import requests -from helpers import LetterFreq, BASE_DICT, get_anagram_hub_id, get_questions +from helpers import get_anagram_hub_id, get_questions parser = argparse.ArgumentParser() parser.add_argument("--name", help="Extension name", dest="name") @@ -24,9 +24,7 @@ auth_header = {"Authorization": args.auth_token} hub_id = get_anagram_hub_id(args.api_url, auth_header) for question in get_questions(args.api_url, auth_header, hub_id): - word = Counter(question) - word.update(BASE_DICT) - word = LetterFreq(**word) + word = "".join(sorted(question)) possible_answers = WORD_DICT[word] for answer in possible_answers: requests.post( diff --git a/helpers.py b/helpers.py index ff5b44d..df715e1 100644 --- a/helpers.py +++ b/helpers.py @@ -18,39 +18,6 @@ WORD_LIST = "wordlist.txt" -LetterFreq = namedtuple( - "LetterFreq", "a b c d e f g h i j k l m n o p q r s t u v w x y z" -) - -BASE_DICT = { - "a": 0, - "b": 0, - "c": 0, - "d": 0, - "e": 0, - "f": 0, - "g": 0, - "h": 0, - "i": 0, - "j": 0, - "k": 0, - "l": 0, - "m": 0, - "n": 0, - "o": 0, - "p": 0, - "q": 0, - "r": 0, - "s": 0, - "t": 0, - "u": 0, - "v": 0, - "w": 0, - "x": 0, - "y": 0, - "z": 0, -} - def get_anagram_hub_id(api_url: str, auth_header: dict) -> int: """Return the seesion_id for anagram game hub.""" @@ -89,16 +56,14 @@ def make_dict(word_list: str) -> None: Open word_list and create/overwite word_dict.pickle with the contents of processed list. """ word_dict = {} - with open(word_dict) as f: + with open(word_list) as f: for word in f: word = word.strip() - word_hash = Counter(word) - word_hash.update(BASE_DICT) - word_hash = LetterFreq(**word_hash) + word_key = "".join(sorted(word)) try: - word_dict[word_hash].append(word) + word_dict[word_key].append(word) except KeyError: - word_dict[word_hash] = [word] + word_dict[word_key] = [word] with open("word_dict.pickle", "bw+") as f: pickle.dump(word_dict, f) diff --git a/word_dict.pickle b/word_dict.pickle index 9a27914..d99eeeb 100644 Binary files a/word_dict.pickle and b/word_dict.pickle differ