Python program to check whether the two strings are #anagram or not... #python #pythonprogramming

preview_player
Показать описание
In this video, you will learn how to check whether the given strings are anagrams of each other or not in Python.

ANAGRAM- An anagram of a string is another string that contains the same characters, only the order of characters can be different. For example, “abcd” and “dabc” are an anagram of each other.
An Anagram is a word or phrase that is formed by rearranging all the letters of a different word or phrase exactly once such as elbow and below.

The question is to write a Python program to check if two strings are anagrams -------
HERE THE CODE IS:-----

a1=input("Enter a string:")
b1=input("Enter a string:")
if len(a1)==len(b1):
sorteda1=sorted(a1)
sortedb1=sorted(b1)
if sorteda1==sortedb1:
print("Strings are anagram")
else:
print("Strings are not anagram")
else:
print("Strings are not anagram")

EXPLANATION----
This Python program checks if two input strings are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase.

Here's a breakdown of how the code works:---

1)It prompts the user to enter two strings (a1 and b1).
2)It converts both input strings to lowercase using the lower() method.
3)This ensures that the comparison is case-insensitive.
4)It checks if the lengths of both strings are equal. If they are not equal, the program prints "Strings are not anagram" and exits.
5)If the lengths are equal, it sorts both strings using the sorted() function, which returns a sorted list of the characters in the string.
6)It then compares the sorted versions of both strings. If they are equal, it prints "Strings are anagram"; otherwise, it prints "Strings are not anagram".
Overall, the code efficiently checks whether two strings are anagrams by converting them to lowercase, sorting their characters, and comparing the sorted versions.

Instagram Link-----

#pythonprogramming #anagrams #stringmanipulation #codingchallenge #programmingtutorial #algorithm #pythontutorial #codingtips #programminglogic #techtutorial #softwaredevelopment #computerscience #codewithme #pythoncode #pycodelabs #pythonprogramminglanguage #programming #coding #python #programmer #program #programminglife #subscribe
Рекомендации по теме
visit shbcf.ru