From d975c8a23f78a7093f225982eadd059a3c048ad1 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 06:12:43 +0000 Subject: [PATCH 1/2] [Sync Iteration] python/anagram/1 --- solutions/python/anagram/1/anagram.py | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 solutions/python/anagram/1/anagram.py diff --git a/solutions/python/anagram/1/anagram.py b/solutions/python/anagram/1/anagram.py new file mode 100644 index 0000000..32e75ea --- /dev/null +++ b/solutions/python/anagram/1/anagram.py @@ -0,0 +1,30 @@ +""" +Anagram. + +Given a target word and one or more candidate words, +your task is to find the candidates that are anagrams +of the target. +""" + + +def find_anagrams(word: str, candidates: list[str]) -> list[str]: + """ + Return the list of candidates that are anagrams of ``word``. + + Two words are considered anagrams if they consist of the same letters + with the same multiplicities when case is ignored. The original casing of + candidates is preserved in the returned list. Exact same word (case-insensitive) + as the target is excluded. + + :param word: Target word to compare against. + :param candidates: Sequence of candidate words to test. + :returns: A list containing each candidate that is an anagram of ``word``. + """ + word_ordered_lower_chars: list[str] = sorted(char.lower() for char in word) + word_lower = word.lower() + return [ + candidate + for candidate in candidates + if candidate.lower() != word_lower + and sorted(char for char in candidate.lower()) == word_ordered_lower_chars + ] From 8177a09dd4b80cf5d531d43abc13440112d54251 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Wed, 26 Nov 2025 06:21:11 +0000 Subject: [PATCH 2/2] [Sync Iteration] python/anagram/2 --- solutions/python/anagram/2/anagram.py | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 solutions/python/anagram/2/anagram.py diff --git a/solutions/python/anagram/2/anagram.py b/solutions/python/anagram/2/anagram.py new file mode 100644 index 0000000..8c01b8a --- /dev/null +++ b/solutions/python/anagram/2/anagram.py @@ -0,0 +1,31 @@ +""" +Anagram. + +Given a target word and one or more candidate words, +your task is to find the candidates that are anagrams +of the target. +""" + + +def find_anagrams(word: str, candidates: list[str]) -> list[str]: + """ + Return the list of candidates that are anagrams of ``word``. + + Two words are considered anagrams if they consist of the same letters + with the same multiplicities when case is ignored. The original casing of + candidates is preserved in the returned list. Exact same word (case-insensitive) + as the target is excluded. + + :param word: Target word to compare against. + :param candidates: Sequence of candidate words to test. + :returns: A list containing each candidate that is an anagram of ``word``. + """ + target_sorted: list[str] = sorted(word.lower()) + target_lower: str = word.lower() + + return [ + candidate + for candidate in candidates + if candidate.lower() != target_lower + and sorted(candidate.lower()) == target_sorted + ]