Python program to check if two strings are anagram or not

Problem: This is a python program that takes two strings and checks if given strings are anagram or not.

Examples:

Solution:

  1. Take two strings from the user and store them in a different variable.
  2. Sort both strings into a list using the sorted() function.
  3. Compare both the result and check if both are equal.
  4. Print the result.
  5. End.

The following is a source code to detect string anagram in Python:

Output

CASE 1:

check if two strings are anagram

CASE 2

check if two strings are anagram

Explanation: In this code, we first need to enter the two strings and store them in a separate variable. Second, both string’s characters are sorted into separate lists and then use if statements to verify whether strings are anagram or not. If both the sorted strings matches, it will display the strings are an anagram. If they are not matched, it will display the string is not an anagram.

Pin It on Pinterest

Share This