Anagram strings represent the same characters in both strings.
exp: ART and RAT
both strings contain the same characters so these strings are anagrams.
Video Code
def anagrams(s1, s2):
Remove spaces and convert to lowercase for case-insensitive comparison
s1 = s1.replace(" ", "").lower()
s2 = s2.replace(" ", "").lower()
Check if the sorted characters are the same
return sorted(str1) == sorted(str2)
Example usage:
str1 = "ART"
str2 = "RAT"
result = anagrams(string1, string2)
print(f"Are '{string1}' and '{string2}' anagrams? ")
print(result)
コメント