| 1 | 1 | def 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) |