From fbd29773cb7814a0a0f34206efff5f21b51132f7 Mon Sep 17 00:00:00 2001 From: Vijayalaxmi Wakode Date: Fri, 4 Oct 2024 03:26:22 +0530 Subject: [PATCH 1/9] The string manipulation - replace() --- strings/replace.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 strings/replace.py diff --git a/strings/replace.py b/strings/replace.py new file mode 100644 index 000000000000..a22d70e76b97 --- /dev/null +++ b/strings/replace.py @@ -0,0 +1,21 @@ +def string_replace(text: str, input_string: str, replace_with_string: str, occurrence: int) -> str: + """ + The replace() method replaces a specified string with another specified string. + The occurence parameter can be skipped in order to consider all text. + Note: input and replace_with strings are case-sensitive. + >>> text = "One Two Two Three Four Five" + >>> string_val = string_replace(text, "Two", "Seven", 1) + >>> print(string_val) + One Seven Two Three Four Five + + >>> text = "In the morning, the cat is running behind the mouse." + >>> string_val = string_replace(text, "the", "a", 10) + >>> print(string_val) + In a morning, a cat is running behind a mouse. + """ + return text.replace(input_string, replace_with_string, occurrence) + + +if __name__ == "__main__": + from doctest import testmod + testmod() From 19db3e369ffd0c4c8a1420f6f7fb9895b5ed6a0f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 21:57:56 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/replace.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/strings/replace.py b/strings/replace.py index a22d70e76b97..9b2494c3a81b 100644 --- a/strings/replace.py +++ b/strings/replace.py @@ -1,4 +1,6 @@ -def string_replace(text: str, input_string: str, replace_with_string: str, occurrence: int) -> str: +def string_replace( + text: str, input_string: str, replace_with_string: str, occurrence: int +) -> str: """ The replace() method replaces a specified string with another specified string. The occurence parameter can be skipped in order to consider all text. @@ -18,4 +20,5 @@ def string_replace(text: str, input_string: str, replace_with_string: str, occur if __name__ == "__main__": from doctest import testmod + testmod() From ce03ae68226579d676cbbe71d4f7d5104f7b94d9 Mon Sep 17 00:00:00 2001 From: Vijayalaxmi Wakode Date: Fri, 4 Oct 2024 03:35:06 +0530 Subject: [PATCH 3/9] Update replace.py --- strings/replace.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/strings/replace.py b/strings/replace.py index 9b2494c3a81b..967e251f2c69 100644 --- a/strings/replace.py +++ b/strings/replace.py @@ -1,9 +1,8 @@ -def string_replace( - text: str, input_string: str, replace_with_string: str, occurrence: int -) -> str: +def string_replace(text: str, input_string: str, replace_with_string: str, occurrence: int) -> str: """ + https://docs.python.org/3/library/stdtypes.html#str.replace The replace() method replaces a specified string with another specified string. - The occurence parameter can be skipped in order to consider all text. + The occurrence parameter can be skipped in order to consider all text. Note: input and replace_with strings are case-sensitive. >>> text = "One Two Two Three Four Five" >>> string_val = string_replace(text, "Two", "Seven", 1) @@ -20,5 +19,4 @@ def string_replace( if __name__ == "__main__": from doctest import testmod - testmod() From b4ec916773448bbd4cde08a6caa54d119984eed4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 22:05:57 +0000 Subject: [PATCH 4/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/replace.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/strings/replace.py b/strings/replace.py index 967e251f2c69..16ef7cbba420 100644 --- a/strings/replace.py +++ b/strings/replace.py @@ -1,4 +1,6 @@ -def string_replace(text: str, input_string: str, replace_with_string: str, occurrence: int) -> str: +def string_replace( + text: str, input_string: str, replace_with_string: str, occurrence: int +) -> str: """ https://docs.python.org/3/library/stdtypes.html#str.replace The replace() method replaces a specified string with another specified string. @@ -19,4 +21,5 @@ def string_replace(text: str, input_string: str, replace_with_string: str, occur if __name__ == "__main__": from doctest import testmod + testmod() From 9f6633c9b951bc36bf0ba68b495c18ab4c2925bf Mon Sep 17 00:00:00 2001 From: vijayalaxmi777 Date: Mon, 14 Oct 2024 18:39:06 +0000 Subject: [PATCH 5/9] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index f0a34a553946..b3891a3cbe8c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1314,6 +1314,7 @@ * [Prefix Function](strings/prefix_function.py) * [Rabin Karp](strings/rabin_karp.py) * [Remove Duplicate](strings/remove_duplicate.py) + * [Replace](strings/replace.py) * [Reverse Letters](strings/reverse_letters.py) * [Reverse Words](strings/reverse_words.py) * [Snake Case To Camel Pascal Case](strings/snake_case_to_camel_pascal_case.py) From 07fe40d4f4865684729dc4b001d0802ad59e67ff Mon Sep 17 00:00:00 2001 From: Vijayalaxmi Wakode Date: Tue, 15 Oct 2024 01:13:35 +0530 Subject: [PATCH 6/9] Add doc test to bubble_sort --- sorts/bubble_sort.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index bdf85c70dd35..9ed09c1c1434 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -85,6 +85,8 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7] >>> bubble_sort_recursive([1, 3.3, 5, 7.7, 2, 4.4, 6]) [1, 2, 3.3, 4.4, 5, 6, 7.7] + >>> bubble_sort_recursive(['a', 'Z','B', 'C', 'A', 'c']) + ['A', 'B', 'C', 'Z', 'a', 'c'] >>> import random >>> collection_arg = random.sample(range(-50, 50), 100) >>> bubble_sort_recursive(collection_arg) == sorted(collection_arg) From 8295014262bc97b3002f746c25958c8a2c5a9555 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Fri, 24 Jan 2025 00:54:42 +0300 Subject: [PATCH 7/9] Update DIRECTORY.md --- DIRECTORY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index b3891a3cbe8c..f0a34a553946 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -1314,7 +1314,6 @@ * [Prefix Function](strings/prefix_function.py) * [Rabin Karp](strings/rabin_karp.py) * [Remove Duplicate](strings/remove_duplicate.py) - * [Replace](strings/replace.py) * [Reverse Letters](strings/reverse_letters.py) * [Reverse Words](strings/reverse_words.py) * [Snake Case To Camel Pascal Case](strings/snake_case_to_camel_pascal_case.py) From fd80bf37facdd099d75c34e41cbcd5a3d7e95371 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Fri, 24 Jan 2025 00:54:54 +0300 Subject: [PATCH 8/9] Delete strings/replace.py --- strings/replace.py | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 strings/replace.py diff --git a/strings/replace.py b/strings/replace.py deleted file mode 100644 index 16ef7cbba420..000000000000 --- a/strings/replace.py +++ /dev/null @@ -1,25 +0,0 @@ -def string_replace( - text: str, input_string: str, replace_with_string: str, occurrence: int -) -> str: - """ - https://docs.python.org/3/library/stdtypes.html#str.replace - The replace() method replaces a specified string with another specified string. - The occurrence parameter can be skipped in order to consider all text. - Note: input and replace_with strings are case-sensitive. - >>> text = "One Two Two Three Four Five" - >>> string_val = string_replace(text, "Two", "Seven", 1) - >>> print(string_val) - One Seven Two Three Four Five - - >>> text = "In the morning, the cat is running behind the mouse." - >>> string_val = string_replace(text, "the", "a", 10) - >>> print(string_val) - In a morning, a cat is running behind a mouse. - """ - return text.replace(input_string, replace_with_string, occurrence) - - -if __name__ == "__main__": - from doctest import testmod - - testmod() From 84e235bd33213ca8d367b37209a1477cf3ddf6fc Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Fri, 24 Jan 2025 00:59:25 +0300 Subject: [PATCH 9/9] Update bubble_sort.py --- sorts/bubble_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorts/bubble_sort.py b/sorts/bubble_sort.py index 9ed09c1c1434..9ec3d5384f38 100644 --- a/sorts/bubble_sort.py +++ b/sorts/bubble_sort.py @@ -85,7 +85,7 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]: [1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7] >>> bubble_sort_recursive([1, 3.3, 5, 7.7, 2, 4.4, 6]) [1, 2, 3.3, 4.4, 5, 6, 7.7] - >>> bubble_sort_recursive(['a', 'Z','B', 'C', 'A', 'c']) + >>> bubble_sort_recursive(['a', 'Z', 'B', 'C', 'A', 'c']) ['A', 'B', 'C', 'Z', 'a', 'c'] >>> import random >>> collection_arg = random.sample(range(-50, 50), 100)