#Basics
Checking if two words are anagrams
Code:
from collections import Counter
def is_anagram(str1, str2):
return Counter(str1) == Counter(str2)
# or without having to import anything
def is_anagram(str1, str2):
return sorted(str1) == sorted(str2)
print(is_anagram('code', 'doce'))
print(is_anagram('python', 'yton'))
Output:
True
False
Share and Support
@Python_Codes
>>Click here to continue<<