Challenges • Asked about 5 years ago by LeeKayBee
Hi, I'm having trouble with Is An Anagram.
I would like to think I have the correct code but it is giving me fails on the test.
It returns False in pycharm when using Mary and Army but here it gives me a fail. It should return False according to testcases and it does in PyCharm but here it gives me a fail. What am I missing?
My code:
def is_anagram(str1, str2):
len1 = len(str1)
len2 = len(str2)
if len1 == len2:
if sorted(str1) == sorted(str2):
return str1 == str2
else:
return str1 == str2
is_anagram("Mary", "Army")
Think casing
Hi LeeKayBee,
Yes, you're going to want to use lower()
(https://www.tutorialspoint.com/python/string_lower.htm) to ensure all the characters are lower-cased.
Click "Solutions" to see our AlgoDaily solution!