mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
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:
parent
f340bde6e0
commit
0c5f1c0130
|
@ -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}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user