-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanagram_checker.py
More file actions
26 lines (21 loc) · 780 Bytes
/
Copy pathanagram_checker.py
File metadata and controls
26 lines (21 loc) · 780 Bytes
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
# Check the word whether it is anagram or not!
# Anagram: The word which letters are same with another word but the sorting is different
def is_anagram(word1: str, word2: str) -> bool:
word1 = word1.lower().replace(" ", "")
word2 = word2.lower().replace(" ", "")
return sorted(word1) == sorted(word2)
if __name__ == "__main__":
test_cases = [
("listen", "silent"), # True
("elbow", "below"), # True
("Dormitory", "Dirty room"), # True
("hello", "world"), # False
("python", "typhon"), # True
("apple", "pale"), # False
]
for w1, w2 in test_cases:
print(
f"{w1} and {w2} are ANAGRAM"
if is_anagram(w1, w2)
else f"{w1} and {w2} are NOT ANAGRAM"
)