From 26180af1d29374c30bf74f11c8c548521215025f Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:35:41 +0530 Subject: [PATCH 01/13] Create swap-case.py This Program will swap the cases of given string --- strings/swap-case.py | 22 ++++++++++++++++++++++ 1 file changed, 22 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..49293ab13178 --- /dev/null +++ b/strings/swap-case.py @@ -0,0 +1,22 @@ +def swap_case(s): + #This method will swap the cases of a given string + # eg: input: s= "Hello" output: t="hELLO" + m=list(s) + for i in range(len(m)): + if m[i]>='A' and m[i]<='Z': + m2=ord(m[i]) + m1=m2+32 + m[i]=chr(m1) + elif m[i]>='a' and m[i]<='z': + m3=ord(m[i]) + m4=m3-32 + m[i]=chr(m4) + else: + pass + t=[ele for ele in m] + t="".join(t) + return t + +s=input() +sc= swap_case(s) +print(sc) From 93f12f4bc90b3dd84f80dd16deb734a6f7f6fbdd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:21:26 +0000 Subject: [PATCH 02/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/swap-case.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/strings/swap-case.py b/strings/swap-case.py index 49293ab13178..c3714affca44 100644 --- a/strings/swap-case.py +++ b/strings/swap-case.py @@ -1,22 +1,23 @@ def swap_case(s): - #This method will swap the cases of a given string + # This method will swap the cases of a given string # eg: input: s= "Hello" output: t="hELLO" - m=list(s) + m = list(s) for i in range(len(m)): - if m[i]>='A' and m[i]<='Z': - m2=ord(m[i]) - m1=m2+32 - m[i]=chr(m1) - elif m[i]>='a' and m[i]<='z': - m3=ord(m[i]) - m4=m3-32 - m[i]=chr(m4) + if m[i] >= "A" and m[i] <= "Z": + m2 = ord(m[i]) + m1 = m2 + 32 + m[i] = chr(m1) + elif m[i] >= "a" and m[i] <= "z": + m3 = ord(m[i]) + m4 = m3 - 32 + m[i] = chr(m4) else: pass - t=[ele for ele in m] - t="".join(t) + t = [ele for ele in m] + t = "".join(t) return t -s=input() -sc= swap_case(s) + +s = input() +sc = swap_case(s) print(sc) From 2fcf33764b8bad50f50568dad93022acdd4fb4a6 Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:12:35 +0530 Subject: [PATCH 03/13] swapcase.py This Method will swap the cases of given string --- strings/swap-case.py | 23 ----------------------- strings/swapcase.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 23 deletions(-) delete mode 100644 strings/swap-case.py create mode 100644 strings/swapcase.py diff --git a/strings/swap-case.py b/strings/swap-case.py deleted file mode 100644 index c3714affca44..000000000000 --- a/strings/swap-case.py +++ /dev/null @@ -1,23 +0,0 @@ -def swap_case(s): - # This method will swap the cases of a given string - # eg: input: s= "Hello" output: t="hELLO" - m = list(s) - for i in range(len(m)): - if m[i] >= "A" and m[i] <= "Z": - m2 = ord(m[i]) - m1 = m2 + 32 - m[i] = chr(m1) - elif m[i] >= "a" and m[i] <= "z": - m3 = ord(m[i]) - m4 = m3 - 32 - m[i] = chr(m4) - else: - pass - t = [ele for ele in m] - t = "".join(t) - return t - - -s = input() -sc = swap_case(s) -print(sc) diff --git a/strings/swapcase.py b/strings/swapcase.py new file mode 100644 index 000000000000..eb2e9462b490 --- /dev/null +++ b/strings/swapcase.py @@ -0,0 +1,33 @@ +""" +Example to show how this method works + +>>> swap_case ("Hello") +hELLO + +>>> swap_case ("water") +WATER +""" + + +def swap_case(input_string) -> str: + """This method will swap the cases of a given string + eg: input: input_string= "Hello" output: swapped_string="hELLO" """ + list_representation=list(input_string) + for i in range(len(list_representation)): + if list_representation[i]>='A' and list_representation[i]<='Z': + m2=ord(list_representation[i]) + m1=m2+32 + list_representation[i]=chr(m1) + elif list_representation[i]>='a' and list_representation[i]<='z': + m3=ord(list_representation[i]) + m4=m3-32 + list_representation[i]=chr(m4) + else: + pass + swapped_list=[ele for ele in list_representation] + swapped_list="".join(swapped_list) + return swapped_list + +input_string=input() +swapped_string= swap_case(input_string) +print(swapped_string) From 23fa94194a9300631d36e91440149b88c1710f64 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:46:11 +0000 Subject: [PATCH 04/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/swapcase.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index eb2e9462b490..e303ce3467e8 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -12,22 +12,23 @@ def swap_case(input_string) -> str: """This method will swap the cases of a given string eg: input: input_string= "Hello" output: swapped_string="hELLO" """ - list_representation=list(input_string) + list_representation = list(input_string) for i in range(len(list_representation)): - if list_representation[i]>='A' and list_representation[i]<='Z': - m2=ord(list_representation[i]) - m1=m2+32 - list_representation[i]=chr(m1) - elif list_representation[i]>='a' and list_representation[i]<='z': - m3=ord(list_representation[i]) - m4=m3-32 - list_representation[i]=chr(m4) + if list_representation[i] >= "A" and list_representation[i] <= "Z": + m2 = ord(list_representation[i]) + m1 = m2 + 32 + list_representation[i] = chr(m1) + elif list_representation[i] >= "a" and list_representation[i] <= "z": + m3 = ord(list_representation[i]) + m4 = m3 - 32 + list_representation[i] = chr(m4) else: pass - swapped_list=[ele for ele in list_representation] - swapped_list="".join(swapped_list) + swapped_list = [ele for ele in list_representation] + swapped_list = "".join(swapped_list) return swapped_list -input_string=input() -swapped_string= swap_case(input_string) + +input_string = input() +swapped_string = swap_case(input_string) print(swapped_string) From b6ea05acca997f02bce81c45ccb942b4ab37b025 Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:28:24 +0530 Subject: [PATCH 05/13] Update swapcase.py --- strings/swapcase.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index e303ce3467e8..9023d6aaf65a 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -24,8 +24,7 @@ def swap_case(input_string) -> str: list_representation[i] = chr(m4) else: pass - swapped_list = [ele for ele in list_representation] - swapped_list = "".join(swapped_list) + swapped_list = "".join(list_representation) return swapped_list From bd75c720e6f693f62d40712a119df35a6a0c54f1 Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Fri, 4 Oct 2024 18:36:58 +0530 Subject: [PATCH 06/13] Update swapcase.py --- strings/swapcase.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index 9023d6aaf65a..9106d456a350 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -27,7 +27,7 @@ def swap_case(input_string) -> str: swapped_list = "".join(list_representation) return swapped_list - -input_string = input() +#sample test case +input_string = "Hello" swapped_string = swap_case(input_string) print(swapped_string) From 49cdb16868229413850897dd8608c7274299222b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 13:08:50 +0000 Subject: [PATCH 07/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/swapcase.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index 9106d456a350..e615ce9f7020 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -27,7 +27,8 @@ def swap_case(input_string) -> str: swapped_list = "".join(list_representation) return swapped_list -#sample test case + +# sample test case input_string = "Hello" swapped_string = swap_case(input_string) print(swapped_string) From 04e84b9105b527d7714d3e68f9e0de33805f04d1 Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Sat, 5 Oct 2024 11:36:27 +0530 Subject: [PATCH 08/13] Update swapcase.py --- strings/swapcase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index e615ce9f7020..49b4bb4497b1 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -9,7 +9,7 @@ """ -def swap_case(input_string) -> str: +def swap_case(input_string : str) -> str: """This method will swap the cases of a given string eg: input: input_string= "Hello" output: swapped_string="hELLO" """ list_representation = list(input_string) From 0a7d2152214a3d6aa3397967febea274412e13d0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Oct 2024 06:06:49 +0000 Subject: [PATCH 09/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/swapcase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index 49b4bb4497b1..bf8c2cf1b067 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -9,7 +9,7 @@ """ -def swap_case(input_string : str) -> str: +def swap_case(input_string: str) -> str: """This method will swap the cases of a given string eg: input: input_string= "Hello" output: swapped_string="hELLO" """ list_representation = list(input_string) From 82c1de334cf2ffb2e648264aa02d9e5e1a6034b9 Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Sat, 5 Oct 2024 11:49:51 +0530 Subject: [PATCH 10/13] Update swapcase.py --- strings/swapcase.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index bf8c2cf1b067..f40d8a431ba1 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -27,8 +27,27 @@ def swap_case(input_string: str) -> str: swapped_list = "".join(list_representation) return swapped_list +def swap_case(input_string) -> None: + #This method will swap the cases of a given string + # eg: input: s= "Hello" output: t="hELLO" + list_representation=list(input_string) + for i in range(len(list_representation)): + if list_representation[i]>='A' and list_representation[i]<='Z': + m2=ord(list_representation[i]) + m1=m2+32 + list_representation[i]=chr(m1) + elif list_representation[i]>='a' and list_representation[i]<='z': + m3=ord(list_representation[i]) + m4=m3-32 + list_representation[i]=chr(m4) + else: + pass + swapped_list=[ele for ele in list_representation] + swapped_list="".join(swapped_list) + return swapped_list -# sample test case -input_string = "Hello" -swapped_string = swap_case(input_string) -print(swapped_string) +if __name__ == "__main__": + # sample test case + input_string = "Hello" + swapped_string = swap_case(input_string) + print(swapped_string) From b8ad822a4382c6ca29a3d5ef08719ff4839b4fb7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Oct 2024 06:20:13 +0000 Subject: [PATCH 11/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/swapcase.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index f40d8a431ba1..3171fa878f80 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -27,25 +27,27 @@ def swap_case(input_string: str) -> str: swapped_list = "".join(list_representation) return swapped_list + def swap_case(input_string) -> None: - #This method will swap the cases of a given string + # This method will swap the cases of a given string # eg: input: s= "Hello" output: t="hELLO" - list_representation=list(input_string) + list_representation = list(input_string) for i in range(len(list_representation)): - if list_representation[i]>='A' and list_representation[i]<='Z': - m2=ord(list_representation[i]) - m1=m2+32 - list_representation[i]=chr(m1) - elif list_representation[i]>='a' and list_representation[i]<='z': - m3=ord(list_representation[i]) - m4=m3-32 - list_representation[i]=chr(m4) + if list_representation[i] >= "A" and list_representation[i] <= "Z": + m2 = ord(list_representation[i]) + m1 = m2 + 32 + list_representation[i] = chr(m1) + elif list_representation[i] >= "a" and list_representation[i] <= "z": + m3 = ord(list_representation[i]) + m4 = m3 - 32 + list_representation[i] = chr(m4) else: pass - swapped_list=[ele for ele in list_representation] - swapped_list="".join(swapped_list) + swapped_list = [ele for ele in list_representation] + swapped_list = "".join(swapped_list) return swapped_list + if __name__ == "__main__": # sample test case input_string = "Hello" From b7d9935039feba829b3056153a4207f9a7e187c2 Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Sat, 5 Oct 2024 11:52:21 +0530 Subject: [PATCH 12/13] Update swapcase.py --- strings/swapcase.py | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/strings/swapcase.py b/strings/swapcase.py index 3171fa878f80..8f068c4d1777 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -27,27 +27,6 @@ def swap_case(input_string: str) -> str: swapped_list = "".join(list_representation) return swapped_list - -def swap_case(input_string) -> None: - # This method will swap the cases of a given string - # eg: input: s= "Hello" output: t="hELLO" - list_representation = list(input_string) - for i in range(len(list_representation)): - if list_representation[i] >= "A" and list_representation[i] <= "Z": - m2 = ord(list_representation[i]) - m1 = m2 + 32 - list_representation[i] = chr(m1) - elif list_representation[i] >= "a" and list_representation[i] <= "z": - m3 = ord(list_representation[i]) - m4 = m3 - 32 - list_representation[i] = chr(m4) - else: - pass - swapped_list = [ele for ele in list_representation] - swapped_list = "".join(swapped_list) - return swapped_list - - if __name__ == "__main__": # sample test case input_string = "Hello" From 1d0a433dcd922fa0941dae5c4e14ce90d27b2940 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 5 Oct 2024 06:22:43 +0000 Subject: [PATCH 13/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/swapcase.py | 1 + 1 file changed, 1 insertion(+) diff --git a/strings/swapcase.py b/strings/swapcase.py index 8f068c4d1777..c2b75a99f4e4 100644 --- a/strings/swapcase.py +++ b/strings/swapcase.py @@ -27,6 +27,7 @@ def swap_case(input_string: str) -> str: swapped_list = "".join(list_representation) return swapped_list + if __name__ == "__main__": # sample test case input_string = "Hello"