In: Computer Science
Write a function which takes two words as string arguments and checks whether they are anagrams.
Explanation:
here is the code which has the function anagram taking strings s1 and s2.
Then it checks the strings s1 and s2, and then compares the length and the sorted version of both the strings.
Code:
def anagram(s1, s2):
sorted_s1 = ''
sorted_s2 = ''
for i in sorted(s1):
sorted_s1 = sorted_s1 + i
for i in sorted(s2):
sorted_s2 = sorted_s2 + i
if(len(s1)==len(s2) and sorted_s1==sorted_s2):
return True
else:
return False
print(anagram("abdde", "eddba"))
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!