I’ve tried finding a solution without having to rely on a dictionary. So, I found out about the set() function which seemed to work when clicking the ‘Run Code’ button but not with the ‘Submit Answer’ button. Any idea why? Would it be possible to do this without using a dictionary in the first place? Thanks for your comments.
def are_anagrams(string1,string2): if len(string1) != len(string2): return False for char in string1: if char not in string2: return False elif set(string1) != set(string2): return False else: return True
What actually happened:
Function are_anagrams did not return the expected value.
But it did work for both examples below:
test1_string1 = 'gainly' test1_string2 = 'laying' # Expected output: True test2_string1 = 'banana' test2_string2 = 'bacana' # Expected output: False