Increased Readability Of Variables (#6400)

* Increased Readability Of Variables

* Update anagrams.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update anagrams.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
ok-open-sc 2022-10-30 03:11:17 -04:00 committed by GitHub
parent f340bde6e0
commit 0c5f1c0130
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,15 +26,15 @@ def anagram(my_word: str) -> list[str]:
>>> anagram('final') >>> anagram('final')
['final'] ['final']
""" """
return word_bysig[signature(my_word)] return word_by_signature[signature(my_word)]
data: str = Path(__file__).parent.joinpath("words.txt").read_text(encoding="utf-8") data: str = Path(__file__).parent.joinpath("words.txt").read_text(encoding="utf-8")
word_list = sorted({word.strip().lower() for word in data.splitlines()}) word_list = sorted({word.strip().lower() for word in data.splitlines()})
word_bysig = collections.defaultdict(list) word_by_signature = collections.defaultdict(list)
for word in word_list: for word in word_list:
word_bysig[signature(word)].append(word) word_by_signature[signature(word)].append(word)
if __name__ == "__main__": if __name__ == "__main__":
all_anagrams = {word: anagram(word) for word in word_list if len(anagram(word)) > 1} all_anagrams = {word: anagram(word) for word in word_list if len(anagram(word)) > 1}