Finished
11def find_anagrams(word: str, candidates: list[str]) -> list[str]:
2 pass
2 # Edge Case: Empty target word
3 if not word:
4 return [candidate for candidate in candidates if not candidate]
5
6 # Edge Case: Empty candidates list
7 if not candidates:
8 return []
9
10 # Normalize the target word for comparison (lowercase and sorted)
11 normalized_target = sorted(word.lower())
12 anagrams = []
13
14 for candidate in candidates:
15 # Edge Case: Candidate is None
16 if candidate is None:
17 continue
18
19 # Edge Case: Candidate is not a string
20 if not isinstance(candidate, str):
21 continue
22
23 # Edge Case: Different lengths - cannot be anagrams
24 if len(candidate) != len(word):
25 continue
26
27 # Edge Case: Identical words (case insensitive) - not anagrams of themselves
28 if candidate.lower() == word.lower():
29 continue
30
31 # Check if candidate is an anagram
32 if sorted(candidate.lower()) == normalized_target:
33 anagrams.append(candidate)
34
35 return anagrams
36# Handled Edge Cases: Empty target word, Empty candidates list, Candidate is None, Candidate is not a string, Different lengths, Identical words (case insensitive)
Test NameStatus
test_anagrams_must_use_all_letters_exactly_once
Pass
test_detects_anagram
Pass
test_detects_anagrams_case_insensitively
Pass
test_detects_anagrams_using_case_insensitive_possible_matches
Pass
test_detects_anagrams_using_case_insensitive_subject
Pass
test_detects_multiple_anagrams_with_different_case
Pass
test_detects_three_anagrams
Pass
test_detects_two_anagrams
Pass
test_different_characters_may_have_the_same_bytes
Pass
test_does_not_detect_an_anagram_if_the_original_word_is_repeated
Pass
test_does_not_detect_anagram_subsets
Pass
test_does_not_detect_non_anagrams_with_identical_checksum
Pass
test_handles_case_of_greek_letters
Pass
test_no_matches
Pass
test_words_are_not_anagrams_of_themselves
Pass
test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_completely_different
Pass
test_words_are_not_anagrams_of_themselves_even_if_letter_case_is_partially_different
Pass
test_words_other_than_themselves_can_be_anagrams
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.