Middle
Implement a function to determine if two words are anagrams. Example: кабан — банка
sobes.tech AI
Answer from AI
Anagram is a word formed by rearranging the letters of another word. To check if two words are anagrams, it is enough to verify that they have the same set of letters with the same frequency.
Example implementation in Python:
def are_anagrams(word1, word2):
return sorted(word1.lower()) == sorted(word2.lower())
# Example usage
print(are_anagrams("кабан", "банка")) # False
print(are_anagrams("кабан", "банак")) # True
Here, we convert the words to lowercase, sort the letters, and compare. If the sorted sequences match, the words are anagrams.