Anagram Check

Check whether two strings are anagrams of each other.

BeginnerTopic: String Programs
Back

Python Anagram Check Program

This program helps you to learn the fundamental structure and syntax of Python programming.

Try This Code
# 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

Understanding Anagram Check

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

Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.

Table of Contents