Create a Python method called check anagram() that receives two strings and returns True if one of them is an anagram of the other. Otherwise, the function returns False.
If the two strings include repeated characters but none of the characters repeat at the same location, they are termed anagrams. The strings should all have the same length.
Wherever possible, use case-insensitive comparison.
Here's my code:
def check_anagram(data1,data2):
first = data1.lower()
second = data2.lower()
d1 = []
d2 = []
for i in range(0, len(first)):
d1.append(first[i])
for i in range(0, len(second)):
d2.append(second[i])
for_check1 = sorted(d1)
for_check2 = sorted(d2)
if (for_check1 != for_check2):
return False
count = 0
if (len(d1) == len(d2)):
for i in d1:
for j in d2:
if(i == j):
a = d1.index(i)
b = d2.index(j)
if(a == b):
return False
else:
count += 1
if(count == len(first)):
return True
else:
return False
print(check_anagram("Schoolmaster", "Theclassroom"))
Although this application returns relevant results for string values such as silence, listen, Moonstarrer, Astronomerapple, and mango, it does not return results for the aforementioned two strings (in code)
What instances am I overlooking in this code? How can this be fixed?