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)
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:)
1from collections import defaultdict
2
3def findAnagrams(input_str):
4 anagram = defaultdict(list)
5
6 for word in input_str:
7 anagram[str(sorted(word))].append(word)
8 return list(anagram.values())
9