Problem: We need to write a program in python to check whether the two given numbers are Anagram or not.
What is an Anagram
An anagram is any word which can be used to form another word by rearranging the letters of the original word.
- Tar <=> Rat
- Arc <=> Car
- Elbow <=> Below
- State <=> Taste
- Cider <=> Cried
- Dusty <=> Study
Let see the python program to check anagram word.
w1="act" w2="cat" def main(): if (sorted(w1)==sorted(w2)): print"the words are anagram" else: print'the words are not anagram' main()
the words are anagram
The two words can only be anagram if they are meaningful and are compromised of the same letters. So we are taking two words as inputs (already defined in our case), and sorting it with the help of inbuilt sorted() method. After sorting the words we are comparing them whether they are same or not. If yes then the word combination is an anagram.
Input – act , cat
Sorted – act, act
Both are the same/equal so they are an anagram.
If you have any doubts or suggestion then comment below.