from collections import Counter
def is_anagram(s1, s2):
return Counter(s1) == Counter(s2)
s1 = 'listen'
s2 = 'silent'
s3 = 'runner'
s4 = 'neuron'
print(''listen' is an anagram of 'silent' -> {}'.format(is_anagram(s1, s2)))
print(''runner' is an anagram of 'neuron' -> {}'.format(is_anagram(s3, s4)))
# Output
# 'listen' an anagram of 'silent' -> True
# 'runner' an anagram of 'neuron' -> False
if sorted(s1) == sorted(s2):
print("The strings are anagrams.")
else:
print("The strings aren't anagrams.")
def anagram_checker(first_value, second_value):
if sorted(first_string) == sorted(second_string):
print("The two strings are anagrams of each other.")
out = True
else:
print("The two strings are not anagrams of each other.")
out = False
return out
first_string = input("Provide the first string: ")
second_string = input("Provide the second string: ")
anagram_checker(first_string, second_string)
Print(anagram_checker("python", "typhon"))
True
// for 2 strings s1 and s2 to be anagrams
// both conditions should be True
// 1 their length is same or
len(s1)==len(s2)
// 2 rearranging chars alphabetically make them equal or
sorted(s1)==sorted(s2)
def are_anagrams(first, second):
return len(first) == len(second) and sorted(first) == sorted(second)