forked from TheAlgorithms/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_anagrams.py
33 lines (27 loc) · 972 Bytes
/
check_anagrams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
wiki: https://en.wikipedia.org/wiki/Anagram
"""
def check_anagrams(first_str: str, second_str: str) -> bool:
"""
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
>>> check_anagrams('This is a string', 'Is this a string')
True
>>> check_anagrams('There', 'Their')
False
"""
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.")