Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions strings/anagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def anagram(my_word: str) -> list[str]:
>>> anagram('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")
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:
word_bysig[signature(word)].append(word)
word_by_signature[signature(word)].append(word)

if __name__ == "__main__":
all_anagrams = {word: anagram(word) for word in word_list if len(anagram(word)) > 1}
Expand Down