Anagram Check

Check whether two strings are anagrams of each other.

PythonBeginner
Python
# Program to check anagram strings

s1 = input("Enter first string: ").replace(" ", "").lower()
s2 = input("Enter second string: ").replace(" ", "").lower()

if sorted(s1) == sorted(s2):
    print("Anagram")
else:
    print("Not an anagram")

Output

Enter first string: listen
Enter second string: silent
Anagram

We normalize by removing spaces and lowercasing, then sort the characters and compare.