From 584ce635592e5e3b9a99a1bf1e3775ad45071a75 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Mon, 12 Oct 2020 02:21:22 +0530 Subject: [PATCH 01/23] Removed an extra '=' which was creating an error while running a program. --- strings/naive_string_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/naive_string_search.py b/strings/naive_string_search.py index f28950264121..2cfdf510a3fc 100644 --- a/strings/naive_string_search.py +++ b/strings/naive_string_search.py @@ -39,4 +39,4 @@ def naive_pattern_search(s: str, pattern: str) -> list: if __name__ == "__main__": assert naive_pattern_search("ABCDEFG", "DE") == [3] - print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC') = }") + print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC')}") From 91d8bf35213e45948d5cc78929131f6baa684792 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Mon, 12 Oct 2020 02:30:58 +0530 Subject: [PATCH 02/23] Removed the unexpected expression part. --- sorts/cocktail_shaker_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/cocktail_shaker_sort.py b/sorts/cocktail_shaker_sort.py index 42015abc5f97..9904df1f9a15 100644 --- a/sorts/cocktail_shaker_sort.py +++ b/sorts/cocktail_shaker_sort.py @@ -42,4 +42,4 @@ def cocktail_shaker_sort(unsorted: list) -> list: doctest.testmod() user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] - print(f"{cocktail_shaker_sort(unsorted) = }") + print(f"{cocktail_shaker_sort(unsorted) }") From 8453420dfd805c236be5d949ce35b33ba17399b1 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Mon, 12 Oct 2020 03:10:53 +0530 Subject: [PATCH 03/23] Added program for swap cases in string folder --- strings/swap_case.py | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 strings/swap_case.py diff --git a/strings/swap_case.py b/strings/swap_case.py new file mode 100644 index 000000000000..c48af3ccfd2d --- /dev/null +++ b/strings/swap_case.py @@ -0,0 +1,48 @@ +''' +This algorithm helps you to swap cases. + +User will give input and then program will perform swap cases. + +In other words, convert all lowercase letters to uppercase letters and vice versa. +For example: +1)>>>Please input sentence: Algorithm.Python@89 + aLGORITHM.pYTHON@89 +2)>>>Please input sentence: github.com/mayur200 + GITHUB.COM/MAYUR200 + +Constraints: Length of string should between 1 and 1000 + + +''' +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): + """ + This function will convert all lowercase letters to uppercase letters and vice versa. + >>>swap_case('Algorithm.Python@89') + aLGORITHM.pYTHON@89 + """ + if len(sentence) < 1001: + newstring = '' + for word in sentence: + if word.isupper() == True: + newstring += word.lower() + if word.islower() == True: + newstring += word.upper() + if regexp.search(word): + newstring += word + + else: + raise Exception("Charater length should be between 1 and 1000") + return newstring + + +if __name__ == '__main__': + s = input("Please input sentence:") + result = swap_case(s) + print(result) \ No newline at end of file From c9d1b7d39f7703bffd08335a5e0b1f0f24b1d6d4 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 01:32:06 +0530 Subject: [PATCH 04/23] removed if condition and exchange word with char --- strings/swap_case.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index c48af3ccfd2d..2e89665ce8cb 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -27,18 +27,15 @@ def swap_case(sentence): >>>swap_case('Algorithm.Python@89') aLGORITHM.pYTHON@89 """ - if len(sentence) < 1001: - newstring = '' - for word in sentence: - if word.isupper() == True: - newstring += word.lower() - if word.islower() == True: - newstring += word.upper() - if regexp.search(word): - newstring += word - - else: - raise Exception("Charater length should be between 1 and 1000") + newstring = '' + for char in sentence: + if char.isupper() == True: + newstring += char.lower() + if char.islower() == True: + newstring += char.upper() + if regexp.search(char): + newstring += char + return newstring From 0a512bb9e655115bba8b858716ed5be023573b58 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 01:36:23 +0530 Subject: [PATCH 05/23] added '=' sign which I removed before because of unknowing error from pycharm --- sorts/cocktail_shaker_sort.py | 2 +- strings/naive_string_search.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sorts/cocktail_shaker_sort.py b/sorts/cocktail_shaker_sort.py index 9904df1f9a15..431a88807f6f 100644 --- a/sorts/cocktail_shaker_sort.py +++ b/sorts/cocktail_shaker_sort.py @@ -42,4 +42,4 @@ def cocktail_shaker_sort(unsorted: list) -> list: doctest.testmod() user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] - print(f"{cocktail_shaker_sort(unsorted) }") + print(f"{cocktail_shaker_sort(unsorted)= }") diff --git a/strings/naive_string_search.py b/strings/naive_string_search.py index 2cfdf510a3fc..887480bb2237 100644 --- a/strings/naive_string_search.py +++ b/strings/naive_string_search.py @@ -39,4 +39,4 @@ def naive_pattern_search(s: str, pattern: str) -> list: if __name__ == "__main__": assert naive_pattern_search("ABCDEFG", "DE") == [3] - print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC')}") + print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC')=}") From 0315f02b626f41a25c3e9711205f5a9d1dc628df Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 01:43:09 +0530 Subject: [PATCH 06/23] added space in test --- strings/swap_case.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 2e89665ce8cb..f42abc445b98 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -5,9 +5,9 @@ In other words, convert all lowercase letters to uppercase letters and vice versa. For example: -1)>>>Please input sentence: Algorithm.Python@89 +1)>>> Please input sentence: Algorithm.Python@89 aLGORITHM.pYTHON@89 -2)>>>Please input sentence: github.com/mayur200 +2)>>> Please input sentence: github.com/mayur200 GITHUB.COM/MAYUR200 Constraints: Length of string should between 1 and 1000 @@ -24,7 +24,7 @@ def swap_case(sentence): """ This function will convert all lowercase letters to uppercase letters and vice versa. - >>>swap_case('Algorithm.Python@89') + >>> swap_case('Algorithm.Python@89') aLGORITHM.pYTHON@89 """ newstring = '' From 018bb9f6e7ed13614b451bf23ecffe90c4c57b10 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 01:44:50 +0530 Subject: [PATCH 07/23] removed costraint from problem statement --- strings/swap_case.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index f42abc445b98..9025c6c29677 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -10,9 +10,6 @@ 2)>>> Please input sentence: github.com/mayur200 GITHUB.COM/MAYUR200 -Constraints: Length of string should between 1 and 1000 - - ''' import re ''' From d823ec1904c37028c8202b53d684ea9c071e9bea Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 22:18:24 +0200 Subject: [PATCH 08/23] Update cocktail_shaker_sort.py --- sorts/cocktail_shaker_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/cocktail_shaker_sort.py b/sorts/cocktail_shaker_sort.py index 431a88807f6f..42015abc5f97 100644 --- a/sorts/cocktail_shaker_sort.py +++ b/sorts/cocktail_shaker_sort.py @@ -42,4 +42,4 @@ def cocktail_shaker_sort(unsorted: list) -> list: doctest.testmod() user_input = input("Enter numbers separated by a comma:\n").strip() unsorted = [int(item) for item in user_input.split(",")] - print(f"{cocktail_shaker_sort(unsorted)= }") + print(f"{cocktail_shaker_sort(unsorted) = }") From 94b71b4b8f6f7697aef12306b93f259233a8671e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 22:18:46 +0200 Subject: [PATCH 09/23] Update naive_string_search.py --- strings/naive_string_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/naive_string_search.py b/strings/naive_string_search.py index 887480bb2237..f28950264121 100644 --- a/strings/naive_string_search.py +++ b/strings/naive_string_search.py @@ -39,4 +39,4 @@ def naive_pattern_search(s: str, pattern: str) -> list: if __name__ == "__main__": assert naive_pattern_search("ABCDEFG", "DE") == [3] - print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC')=}") + print(f"{naive_pattern_search('ABAAABCDBBABCDDEBCABC', 'ABC') = }") From f8ae23b4a4c2729c8bf78e13d7d657108b68c473 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 22:20:23 +0200 Subject: [PATCH 10/23] Update swap_case.py --- strings/swap_case.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 9025c6c29677..ff6db5c315b2 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -24,19 +24,17 @@ def swap_case(sentence): >>> swap_case('Algorithm.Python@89') aLGORITHM.pYTHON@89 """ - newstring = '' + new_string = '' for char in sentence: if char.isupper() == True: - newstring += char.lower() + new_string += char.lower() if char.islower() == True: - newstring += char.upper() + new_string += char.upper() if regexp.search(char): - newstring += char + new_string += char - return newstring + return new_string if __name__ == '__main__': - s = input("Please input sentence:") - result = swap_case(s) - print(result) \ No newline at end of file + print(swap_case(input("Please input sentence:"))) From 145ffe03c9df95484750363f791933c3d1a6ae3c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 22:24:34 +0200 Subject: [PATCH 11/23] psf/black " not ' --- strings/swap_case.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index ff6db5c315b2..a9b6507c7310 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -1,4 +1,4 @@ -''' +""" This algorithm helps you to swap cases. User will give input and then program will perform swap cases. @@ -10,12 +10,11 @@ 2)>>> Please input sentence: github.com/mayur200 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]+') + +# 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): @@ -24,7 +23,7 @@ def swap_case(sentence): >>> swap_case('Algorithm.Python@89') aLGORITHM.pYTHON@89 """ - new_string = '' + new_string = "" for char in sentence: if char.isupper() == True: new_string += char.lower() @@ -36,5 +35,5 @@ def swap_case(sentence): return new_string -if __name__ == '__main__': +if __name__ == "__main__": print(swap_case(input("Please input sentence:"))) From 18c8286c819422f3c0d7077b3460adf04c5a6b0a Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 01:54:55 +0530 Subject: [PATCH 12/23] added new line at the end of the file --- strings/swap_case.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 9025c6c29677..911172abcca4 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -39,4 +39,6 @@ def swap_case(sentence): if __name__ == '__main__': s = input("Please input sentence:") result = swap_case(s) - print(result) \ No newline at end of file + print(result) + + From ab606cdea2dd017cccaf8b054b1c993add0f4d60 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 22:29:17 +0200 Subject: [PATCH 13/23] Fix flake8 issues --- strings/swap_case.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index a9b6507c7310..068d6e9b462a 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -13,21 +13,24 @@ """ import re -# This re.compile() function saves the pattern from 'a' to 'z' and 'A' to 'Z' into 'regexp' variable +# 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): """ - This function will convert all lowercase letters to uppercase letters and vice versa. + This function will convert all lowercase letters to uppercase letters and + vice versa. + >>> swap_case('Algorithm.Python@89') aLGORITHM.pYTHON@89 """ new_string = "" for char in sentence: - if char.isupper() == True: + if char.isupper(): new_string += char.lower() - if char.islower() == True: + if char.islower(): new_string += char.upper() if regexp.search(char): new_string += char From 752bc5d401739c8f45416dade9a7e22b05a19743 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 02:05:44 +0530 Subject: [PATCH 14/23] added new line at the end of the file --- strings/swap_case.py | 1 + 1 file changed, 1 insertion(+) diff --git a/strings/swap_case.py b/strings/swap_case.py index a3b32566444b..4f8036207a34 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -43,3 +43,4 @@ def swap_case(sentence): result = swap_case(s) print(result) + From ef736199d854b178fbf96905b23f4f67a204076f Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 02:12:37 +0530 Subject: [PATCH 15/23] added True and fixed comment --- strings/swap_case.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 4f8036207a34..9e6d15f01f02 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -13,26 +13,24 @@ """ import re -# This re.compile() function saves the pattern from 'a' to 'z' and 'A' to 'Z' -# into 'regexp' variable +# 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): """ - This function will convert all lowercase letters to uppercase letters and - vice versa. + This function will convert all lowercase letters to uppercase letters and vice versa. >>> swap_case('Algorithm.Python@89') aLGORITHM.pYTHON@89 """ new_string = "" for char in sentence: - if char.isupper(): + if char.isupper() == True: new_string += char.lower() - if char.islower(): + if char.islower() == True: new_string += char.upper() - if regexp.search(char): + if regexp.search(char) == True: new_string += char return new_string From 353eaed17435504cd30eed5443963aa9badae2c2 Mon Sep 17 00:00:00 2001 From: mayur200 Date: Thu, 15 Oct 2020 03:11:11 +0530 Subject: [PATCH 16/23] python file end with \n --- strings/swap_case.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 9e6d15f01f02..f36fc0c52ed7 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -39,6 +39,6 @@ def swap_case(sentence): if __name__ == '__main__': s = input("Please input sentence:") result = swap_case(s) - print(result) + print(result,"\n") From 08209ffb376c020fd35edf223ceaada97cdbf5f1 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 23:49:45 +0200 Subject: [PATCH 17/23] Update swap_case.py --- strings/swap_case.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index f36fc0c52ed7..48a8a480ba2e 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -39,6 +39,4 @@ def swap_case(sentence): if __name__ == '__main__': s = input("Please input sentence:") result = swap_case(s) - print(result,"\n") - - + print(result) From 14024a8b67332dea76f5d8e1ea2002fba2c42610 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 23:57:33 +0200 Subject: [PATCH 18/23] Update strings/swap_case.py --- strings/swap_case.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 48a8a480ba2e..a4e1f5f7e85e 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -37,6 +37,4 @@ def swap_case(sentence): if __name__ == '__main__': - s = input("Please input sentence:") - result = swap_case(s) - print(result) + print(swap_case(input("Please input sentence:"))) From bcfcb2191b2085b7015a129b554e626386c0aac8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 23:57:49 +0200 Subject: [PATCH 19/23] Update strings/swap_case.py --- strings/swap_case.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index a4e1f5f7e85e..95cfbece1a55 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -30,7 +30,7 @@ def swap_case(sentence): new_string += char.lower() if char.islower() == True: new_string += char.upper() - if regexp.search(char) == True: + if regexp.search(char): new_string += char return new_string From 81f89ebd0b3090e936155d3d91385977292d197f Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 23:59:24 +0200 Subject: [PATCH 20/23] Apply suggestions from code review --- strings/swap_case.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index 95cfbece1a55..bd97e1c4078b 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -5,30 +5,32 @@ In other words, convert all lowercase letters to uppercase letters and vice versa. For example: -1)>>> Please input sentence: Algorithm.Python@89 +1. Please input sentence: Algorithm.Python@89 aLGORITHM.pYTHON@89 -2)>>> Please input sentence: github.com/mayur200 +2. Please input sentence: github.com/mayur200 GITHUB.COM/MAYUR200 """ import re -# This re.compile() function saves the pattern from 'a' to 'z' and 'A' to 'Z' into 'regexp' variable +# 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): """ - This function will convert all lowercase letters to uppercase letters and vice versa. + This function will convert all lowercase letters to uppercase letters + and vice versa. >>> swap_case('Algorithm.Python@89') - aLGORITHM.pYTHON@89 + 'aLGORITHMpYTHON``` """ new_string = "" for char in sentence: - if char.isupper() == True: + if char.isupper(): new_string += char.lower() - if char.islower() == True: + if char.islower(): new_string += char.upper() if regexp.search(char): new_string += char @@ -36,5 +38,5 @@ def swap_case(sentence): return new_string -if __name__ == '__main__': +if __name__ == "__main__": print(swap_case(input("Please input sentence:"))) From 421fa61c064603dedfad9053ca547bead7e9b2ff Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 14 Oct 2020 23:59:58 +0200 Subject: [PATCH 21/23] Update strings/swap_case.py --- strings/swap_case.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index bd97e1c4078b..d0027d809494 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -3,7 +3,8 @@ User will give input and then program will perform swap cases. -In other words, convert all lowercase letters to uppercase letters and vice versa. +In other words, convert all lowercase letters to uppercase letters +and vice versa. For example: 1. Please input sentence: Algorithm.Python@89 aLGORITHM.pYTHON@89 From 30863af19fea1699aedb09bd8cddd6d320a81492 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 15 Oct 2020 00:00:17 +0200 Subject: [PATCH 22/23] Update swap_case.py --- strings/swap_case.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index d0027d809494..bd97e1c4078b 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -3,8 +3,7 @@ User will give input and then program will perform swap cases. -In other words, convert all lowercase letters to uppercase letters -and vice versa. +In other words, convert all lowercase letters to uppercase letters and vice versa. For example: 1. Please input sentence: Algorithm.Python@89 aLGORITHM.pYTHON@89 From 79d37c41e15d6981d493e684b32fe54dc68e6e8e Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 15 Oct 2020 00:13:08 +0200 Subject: [PATCH 23/23] Update swap_case.py --- strings/swap_case.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/swap_case.py b/strings/swap_case.py index bd97e1c4078b..71e8aeb3a205 100644 --- a/strings/swap_case.py +++ b/strings/swap_case.py @@ -24,7 +24,7 @@ def swap_case(sentence): and vice versa. >>> swap_case('Algorithm.Python@89') - 'aLGORITHMpYTHON``` + 'aLGORITHM.pYTHON@89' """ new_string = "" for char in sentence: