Python Program to Check If Two Strings are Anagram

preview_player
Показать описание
#BackCoding

Two strings are said to be anagram if we can form one string by arranging the characters of another string. For example, Race and Care. Here, we can form Race by arranging the characters of Care.

We first convert the strings to lowercase. It is because Python is case sensitive (i.e. R and r are two different characters in Python).

#programming
#dcoder
#shorts
#python
Рекомендации по теме
Комментарии
Автор

def anagramWord(str1, str2):
if(len(str1)==len(str2)):
sorted_str1=sorted(str1)
sorted_str2=sorted(str2)
if(sorted_str1==sorted_str2):
print(str1+" and "+str2+" are anagram")
else:
print(str1+" and "+str2+" are not anagram")

else:
print(str1+" and "+str2+" are not anagram")

str1=input("Enter word check anagrams1 :")
str2=input("Enter word check anagrams2 :")

str1=str1.lower()
str2=str2.lower()

anagramWord(str1, str2)

BackCoding