From e5533f8e98f52e484fefd103e620da6462a4cfb4 Mon Sep 17 00:00:00 2001 From: shellhub Date: Thu, 24 Sep 2020 23:25:04 +0800 Subject: [PATCH 1/2] fixed bug --- strings/check_anagrams.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/strings/check_anagrams.py b/strings/check_anagrams.py index 7cc1e2978db9..f55230425aaf 100644 --- a/strings/check_anagrams.py +++ b/strings/check_anagrams.py @@ -1,4 +1,9 @@ -def check_anagrams(a: str, b: str) -> bool: +""" +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). @@ -6,13 +11,18 @@ def check_anagrams(a: str, b: str) -> bool: 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 sorted(a.lower()) == sorted(b.lower()) + 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() From 98aaad3088180d88dd93c1a892bdc373c67a162e Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 24 Sep 2020 15:26:18 +0000 Subject: [PATCH 2/2] fixup! Format Python code with psf/black push --- strings/check_anagrams.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/strings/check_anagrams.py b/strings/check_anagrams.py index f55230425aaf..3083000cbb5d 100644 --- a/strings/check_anagrams.py +++ b/strings/check_anagrams.py @@ -16,7 +16,10 @@ def check_anagrams(first_str: str, second_str: str) -> bool: >>> check_anagrams('There', 'Their') False """ - return "".join(sorted(first_str.lower())).strip() == "".join(sorted(second_str.lower())).strip() + return ( + "".join(sorted(first_str.lower())).strip() + == "".join(sorted(second_str.lower())).strip() + ) if __name__ == "__main__":