Community

Ask A Question


Notifications
Subscribe You’re not receiving notifications from this thread.

Is an anagram

Challenges • Asked 2 months ago by LeeKayBee

Gravatar LeeKayBee Commented on Nov 13, 2019:

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)
len
2 = len(str2)

if len1 == len2:
if sorted(str1) == sorted(str2):
return str1 == str2
else:
return str1 == str2

is_anagram("Mary", "Army")

Gravatar M Commented on Nov 14, 2019:

Think casing

Gravatar Jake from AlgoDaily Commented on Nov 27, 2019:

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!

Terms and Conditions | Privacy