In this program basically we are going check the given string is anagram or not. Before we proceed further let us know something about anagram.
If two words or strings that are made of the same letters but arrange differently & form a new word/ string.
Ex:- Anagram words
'Silent' --> 'Listen' 'This is a string' --> 'Is this a string'
def check_anagrams(first_str: str, second_str: str) -> bool:
return (
"".join(sorted(first_str.lower())).strip()
== "".join(sorted(second_str.lower())).strip()
)
if __name__ == "__main__":
from doctest import testmod
testmod()
input_A = input("Enter the first string ").strip()
input_B = input("Enter the second string ").strip()
status = check_anagrams(input_A, input_B)
print(f"{input_A} and {input_B} are {'' if status else 'not '}anagrams.")
|
0 Comments