Skip to content

Commit a196a36

Browse files
realDuYuanChaogithub-actions
and
github-actions
authored
Fixed bugs (#2474)
* fixed bug * fixup! Format Python code with psf/black push Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 53c2a24 commit a196a36

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

strings/check_anagrams.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,31 @@
1-
def check_anagrams(a: str, b: str) -> bool:
1+
"""
2+
wiki: https://en.wikipedia.org/wiki/Anagram
3+
"""
4+
5+
6+
def check_anagrams(first_str: str, second_str: str) -> bool:
27
"""
38
Two strings are anagrams if they are made of the same letters
49
arranged differently (ignoring the case).
510
>>> check_anagrams('Silent', 'Listen')
611
True
712
>>> check_anagrams('This is a string', 'Is this a string')
813
True
14+
>>> check_anagrams('This is a string', 'Is this a string')
15+
True
916
>>> check_anagrams('There', 'Their')
1017
False
1118
"""
12-
return sorted(a.lower()) == sorted(b.lower())
19+
return (
20+
"".join(sorted(first_str.lower())).strip()
21+
== "".join(sorted(second_str.lower())).strip()
22+
)
1323

1424

1525
if __name__ == "__main__":
26+
from doctest import testmod
27+
28+
testmod()
1629
input_A = input("Enter the first string ").strip()
1730
input_B = input("Enter the second string ").strip()
1831

0 commit comments

Comments
 (0)