2020-09-25 13:20:09 +00:00
|
|
|
"""
|
|
|
|
wiki: https://en.wikipedia.org/wiki/Anagram
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def check_anagrams(first_str: str, second_str: str) -> bool:
|
2020-08-19 16:24:02 +00:00
|
|
|
"""
|
|
|
|
Two strings are anagrams if they are made of the same letters
|
|
|
|
arranged differently (ignoring the case).
|
|
|
|
>>> check_anagrams('Silent', 'Listen')
|
|
|
|
True
|
|
|
|
>>> check_anagrams('This is a string', 'Is this a string')
|
|
|
|
True
|
2020-09-25 13:20:09 +00:00
|
|
|
>>> check_anagrams('This is a string', 'Is this a string')
|
|
|
|
True
|
2020-08-19 16:24:02 +00:00
|
|
|
>>> check_anagrams('There', 'Their')
|
|
|
|
False
|
|
|
|
"""
|
2020-09-25 13:20:09 +00:00
|
|
|
return (
|
|
|
|
"".join(sorted(first_str.lower())).strip()
|
|
|
|
== "".join(sorted(second_str.lower())).strip()
|
|
|
|
)
|
2020-08-19 16:24:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2020-09-25 13:20:09 +00:00
|
|
|
from doctest import testmod
|
|
|
|
|
|
|
|
testmod()
|
2020-08-19 16:24:02 +00:00
|
|
|
input_A = input("Enter the first string ").strip()
|
|
|
|
input_B = input("Enter the second string ").strip()
|
|
|
|
|
|
|
|
status = check_anagrams(input_A, input_B)
|
2020-08-21 06:39:03 +00:00
|
|
|
print(f"{input_A} and {input_B} are {'' if status else 'not '}anagrams.")
|