In this we are going to see a basic program to compare two string to check if they are anagram in Python Programming Language.
str1 = "Care"
str2 = "Race"
str1 = str1.lower()
str2 = str2.lower()
if(len(str1) == len(str2)):
sorted_str1 = sorted(str1)
sorted_str2 = sorted(str2)
if(sorted_str1 == sorted_str2):
print(str1.capitalize() + " And " + str2.capitalize() + " Are Anagram.")
else:
print(str1.capitalize() + " And " + str2.capitalize() + " Are Not Anagram.")
else:
print(str1.capitalize() + " And " + str2.capitalize() + " Are Not Anagram.")
# Coded By DHIRAJ SHELKE
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP