| 1 | 1 | def find_anagrams(word, candidates): |
| 2 | | pass |
| 2 | # Edge Case: Handle None inputs |
| 3 | if word is None or candidates is None: |
| 4 | return [] |
| 5 | |
| 6 | # Edge Case: Handle empty candidates list |
| 7 | if not candidates: |
| 8 | return [] |
| 9 | |
| 10 | # Normalize the target word for comparison (lowercase and sorted) |
| 11 | normalized_word = sorted(word.lower()) |
| 12 | anagrams = [] |
| 13 | |
| 14 | # Edge Case: Handle empty target word |
| 15 | if not word: |
| 16 | for candidate in candidates: |
| 17 | # Edge Case: Candidate is also empty (not an anagram of itself) |
| 18 | if not candidate: |
| 19 | continue |
| 20 | # Edge Case: Non-empty candidate can't be anagram of empty word |
| 21 | else: |
| 22 | continue |
| 23 | |
| 24 | for candidate in candidates: |
| 25 | # Edge Case: Handle None candidate |
| 26 | if candidate is None: |
| 27 | continue |
| 28 | |
| 29 | # Edge Case: Candidate is the same word as target (case insensitive) |
| 30 | if candidate.lower() == word.lower(): |
| 31 | continue |
| 32 | |
| 33 | # Edge Case: Different lengths cannot be anagrams |
| 34 | if len(candidate) != len(word): |
| 35 | continue |
| 36 | |
| 37 | # Check if candidate is an anagram by comparing sorted lowercase letters |
| 38 | if sorted(candidate.lower()) == normalized_word: |
| 39 | anagrams.append(candidate) |
| 40 | |
| 41 | return anagrams |
| 42 | # Handled Edge Cases: None inputs, empty candidates list, empty target word, None candidate, identical words (case insensitive), different length strings |