Skip to content

Commit 2eca716

Browse files
Kush1101cclauss
andauthored
Created check_anagrams.py in strings (TheAlgorithms#2339)
* Add files via upload * Update check_anagrams.py * Update check_anagrams.py * Update check_anagrams.py * Update check_anagrams.py * “” or not Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 9351889 commit 2eca716

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

strings/check_anagrams.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def check_anagrams(a: str, b: str) -> bool:
2+
"""
3+
Two strings are anagrams if they are made of the same letters
4+
arranged differently (ignoring the case).
5+
>>> check_anagrams('Silent', 'Listen')
6+
True
7+
>>> check_anagrams('This is a string', 'Is this a string')
8+
True
9+
>>> check_anagrams('There', 'Their')
10+
False
11+
"""
12+
return sorted(a.lower()) == sorted(b.lower())
13+
14+
15+
if __name__ == "__main__":
16+
input_A = input("Enter the first string ").strip()
17+
input_B = input("Enter the second string ").strip()
18+
19+
status = check_anagrams(input_A, input_B)
20+
print(
21+
f"{input_A} and {input_B} are {'' if status else 'not '}anagrams."
22+
)

0 commit comments

Comments
 (0)