I’m doing exercise about function and stuck at problem 13 - Anagrams. My code worked with provided input, but there is an error when submitting answer.
Can you guys help me take a look at it? Thanks a lot
My Code:
def are_anagrams(string1, string2):
if len(string1) != len(string2):
return False
arr = string1 + string2
freq = {}
for c in arr:
if c in freq:
freq[c] += 1
else:
freq[c] = 1
for c in freq:
if freq[c] == 1:
return False
return True
print(are_anagrams('gainly', 'laying'))
print(are_anagrams('banana', 'bacana'))
What actually happened:
Function are_anagrams did not return the expected value.