From ea3be799d9346876ea943edba43638dcb5e264fb Mon Sep 17 00:00:00 2001 From: Frank Schmitt Date: Sat, 31 Oct 2020 08:58:50 +0100 Subject: [PATCH 1/4] #3847 fix handling of non-ASCII characters in swap_case --- strings/swap_case.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 71e8aeb3a205..36b689a77c1c 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -30,9 +30,9 @@ def swap_case(sentence): for char in sentence: if char.isupper(): new_string += char.lower() - if char.islower(): + elif char.islower(): new_string += char.upper() - if regexp.search(char): + else: new_string += char return new_string From 647f8f090b7d4f3b05f315909dce610e5faced0d Mon Sep 17 00:00:00 2001 From: Frank Schmitt Date: Sat, 31 Oct 2020 09:00:25 +0100 Subject: [PATCH 2/4] #3847 remove unused regex --- strings/swap_case.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 36b689a77c1c..bbe84d4bd3c3 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -11,12 +11,6 @@ GITHUB.COM/MAYUR200 """ -import re - -# This re.compile() function saves the pattern from 'a' to 'z' and 'A' to 'Z' -# into 'regexp' variable -regexp = re.compile("[^a-zA-Z]+") - def swap_case(sentence): """ From f75a3bc341d6f47c7543f3b8e63afc057f4ced47 Mon Sep 17 00:00:00 2001 From: Frank Schmitt Date: Mon, 2 Nov 2020 23:06:55 +0100 Subject: [PATCH 3/4] Fix formatting (with black) Fixes: #3847 --- strings/swap_case.py | 1 + 1 file changed, 1 insertion(+) diff --git a/strings/swap_case.py b/strings/swap_case.py index bbe84d4bd3c3..4c059754d4f9 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -12,6 +12,7 @@ """ + def swap_case(sentence): """ This function will convert all lowercase letters to uppercase letters From b888bb97867d23d8230f278880ae8de054865b5c Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Fri, 6 Nov 2020 22:32:25 +0530 Subject: [PATCH 4/4] Add type hints for `swap_case` function --- strings/swap_case.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 4c059754d4f9..107fda4b52ec 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -13,7 +13,7 @@ """ -def swap_case(sentence): +def swap_case(sentence: str) -> str: """ This function will convert all lowercase letters to uppercase letters and vice versa. @@ -34,4 +34,4 @@ def swap_case(sentence): if __name__ == "__main__": - print(swap_case(input("Please input sentence:"))) + print(swap_case(input("Please input sentence: ")))