1# function to check if two strings are
2# anagram or not
3def check(s1, s2):
4
5 # the sorted strings are checked
6 if(sorted(s1)== sorted(s2)):
7 print("The strings are anagrams.")
8 else:
9 print("The strings aren't anagrams.")
10
11# driver code
12s1 ="listen"
13s2 ="silent"
14check(s1, s2)
1if sorted(s1) == sorted(s2):
2 print("The strings are anagrams.")
3else:
4 print("The strings aren't anagrams.")
1def isAnagram(A,B):
2 if sorted(A) == sorted(B):
3 print("Yes")
4 else:
5 print("No")
6isAnagram("earth","heart") #Output: Yes
7
8#Hope this helps:)
1#take user input
2String1 = input('Enter the 1st string :')
3String2 = input('Enter the 2nd string :')
4#check if length matches
5if len(String1) != len(String2):
6 #if False
7 print('Strings are not anagram')
8else:
9 #sorted function sort string by characters
10 String1 = sorted(String1)
11 String2 = sorted(String2)
12 #check if now strings matches
13 if String1 == String2:
14 #if True
15 print('Strings are anagram')
16 else:
17 print('Strings are not anagram')
1const anagram = (str1, str2) => {
2 return str1.toLowerCase().split('').sort().join('') === str2.toLowerCase().split('').sort().join('');
3};
4
5let test = anagram('Regallager', 'Lagerregal');
6console.log(test);