Contact: aviboots(AT)netvision.net.il
40,772 questions
53,159 answers
573 users
s1 = "python" s2 = "thonpy" if sorted(s1) == sorted(s2): print("Anagram") else: print("Not Anagram") ''' run: Anagram '''
def isAnagram(s1, s2): lens1 = len(s1) lens2 = len(s2) if lens1 != lens2: return 0 s1 = sorted(s1) s2 = sorted(s2) if s1 != s2: return 0 return 1 s1 = "python" s2 = "thonpy" if isAnagram(s1, s2): print("Anagram") else: print("Not Anagram") ''' run: Anagram '''
from collections import Counter def is_anagram(s1, s2): return Counter(s1) == Counter(s2) print(is_anagram('python', 'thonpy')) print(is_anagram('php', 'hpp')) print(is_anagram('c++', 'cpp')) ''' run True True False '''