In this program, we find whether the two given strings are anagram or not, by using python. We will be finding whether the two given strings are anagram to each other.
What is an anagram?
An anagram is a rearrangement of the letters of a word to another word, using all the original letters exactly once.
For example: Input: S1=”listen”
Output: Strings are anagram of each other.
- Input two strings from the user.
- Initialize count=0.
- Using for loop, if i==j then count is increased by 1.
- Using if condition to compare the length of a with count, if true print “it is anagram”.
Anagram python program Code:
a=input("Enter string 1:") b=input("Enter string 2:") count=0 for i in a: for j in b: if i==j: count=count+1 if count==len(a): print("Strings are anagram of each other.") else: print("Strings are not anagram of each other.")
Enter string 1: and Enter string 2: dan Strings are anagram of each other.