From 23a0f955ea206ffee4b195fdd534df6f60084897 Mon Sep 17 00:00:00 2001 From: Sankalpa Sarkar <137193167+sanks011@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:30:10 +0530 Subject: [PATCH 01/12] fixes join.py action --- strings/join.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/strings/join.py b/strings/join.py index 5c02f65a20ce..3c09c112605e 100644 --- a/strings/join.py +++ b/strings/join.py @@ -8,8 +8,7 @@ def join(separator: str, separated: list[str]) -> str: Joins a list of strings using a separator and returns the result. - :param separator: Separator to be used - for joining the strings. + :param separator: Separator to be used for joining the strings. :param separated: List of strings to be joined. :return: Joined string with the specified separator. @@ -20,13 +19,12 @@ def join(separator: str, separated: list[str]) -> str: 'abcd' >>> join("#", ["a", "b", "c", "d"]) 'a#b#c#d' - >>> join("#", "a") + >>> join("#", ["a"]) 'a' >>> join(" ", ["You", "are", "amazing!"]) 'You are amazing!' - This example should raise an - exception for non-string elements: + This example should raise an exception for non-string elements: >>> join("#", ["a", "b", "c", 1]) Traceback (most recent call last): ... @@ -35,18 +33,17 @@ def join(separator: str, separated: list[str]) -> str: Additional test case with a different separator: >>> join("-", ["apple", "banana", "cherry"]) 'apple-banana-cherry' + >>> join(",", ["", "", ""]) + ',,,' # This test will now pass correctly + """ - joined = "" - for word_or_phrase in separated: - if not isinstance(word_or_phrase, str): - raise Exception("join() accepts only strings") - joined += word_or_phrase + separator + if not all(isinstance(word_or_phrase, str) for word_or_phrase in separated): + raise Exception("join() accepts only strings") - # Remove the trailing separator - # by stripping it from the result - return joined.strip(separator) + joined = separator.join(separated) + return joined if __name__ == "__main__": from doctest import testmod From 29b5cc246f07ce79fa85042fe6b3d9c4d0b5d5a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:07:56 +0000 Subject: [PATCH 02/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/join.py | 1 + 1 file changed, 1 insertion(+) diff --git a/strings/join.py b/strings/join.py index 3c09c112605e..2487001d1272 100644 --- a/strings/join.py +++ b/strings/join.py @@ -45,6 +45,7 @@ def join(separator: str, separated: list[str]) -> str: return joined + if __name__ == "__main__": from doctest import testmod From 82434807c7d6f20e1c13504f209fc50871114782 Mon Sep 17 00:00:00 2001 From: Sankalpa Sarkar <137193167+sanks011@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:44:40 +0530 Subject: [PATCH 03/12] fixes split.py --- strings/split.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/strings/split.py b/strings/split.py index b62b86d2401f..60303b7ed0d4 100644 --- a/strings/split.py +++ b/strings/split.py @@ -17,18 +17,21 @@ def split(string: str, separator: str = " ") -> list: """ split_words = [] - last_index = 0 + for index, char in enumerate(string): if char == separator: - split_words.append(string[last_index:index]) + split_words.append(string[last_index:index]) # Add substring between separators last_index = index + 1 - elif index + 1 == len(string): - split_words.append(string[last_index : index + 1]) - return split_words + elif index + 1 == len(string): # If at the last character, handle trailing separator + split_words.append(string[last_index:]) # Add the last part of the string + # If the string ends with a separator, ensure an empty string is added + if string and string[-1] == separator: + split_words.append('') + + return split_words if __name__ == "__main__": from doctest import testmod - testmod() From f6c545f1d9399162383af0e52a62e57e0737fcbb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:15:15 +0000 Subject: [PATCH 04/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/split.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/strings/split.py b/strings/split.py index 60303b7ed0d4..c76541fbc32b 100644 --- a/strings/split.py +++ b/strings/split.py @@ -21,17 +21,23 @@ def split(string: str, separator: str = " ") -> list: for index, char in enumerate(string): if char == separator: - split_words.append(string[last_index:index]) # Add substring between separators + split_words.append( + string[last_index:index] + ) # Add substring between separators last_index = index + 1 - elif index + 1 == len(string): # If at the last character, handle trailing separator + elif index + 1 == len( + string + ): # If at the last character, handle trailing separator split_words.append(string[last_index:]) # Add the last part of the string # If the string ends with a separator, ensure an empty string is added if string and string[-1] == separator: - split_words.append('') + split_words.append("") return split_words + if __name__ == "__main__": from doctest import testmod + testmod() From de9aa38af0ccc9450215b54ac04e9fe3bdefc5dc Mon Sep 17 00:00:00 2001 From: Sankalpa Sarkar <137193167+sanks011@users.noreply.github.com> Date: Mon, 16 Dec 2024 20:10:53 +0530 Subject: [PATCH 05/12] Fixed two requirements --- requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4cc83f44987d..b104505e01bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ beautifulsoup4 -fake_useragent +fake-useragent imageio keras lxml @@ -11,7 +11,7 @@ pillow requests rich scikit-learn -sphinx_pyproject +sphinx-pyproject statsmodels sympy tweepy From 0b45a6da72ec337eb70ce17d76522c89f2dca38e Mon Sep 17 00:00:00 2001 From: Sankalpa Sarkar <137193167+sanks011@users.noreply.github.com> Date: Wed, 18 Dec 2024 11:09:04 +0530 Subject: [PATCH 06/12] Custom Implementation of join.py --- strings/join.py | 52 ++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/strings/join.py b/strings/join.py index 2487001d1272..a60b8fbb30ab 100644 --- a/strings/join.py +++ b/strings/join.py @@ -1,49 +1,27 @@ -""" -Program to join a list of strings with a separator -""" - - def join(separator: str, separated: list[str]) -> str: """ - Joins a list of strings using a separator - and returns the result. - - :param separator: Separator to be used for joining the strings. - :param separated: List of strings to be joined. - - :return: Joined string with the specified separator. + Custom implementation of the join() function. + This function manually concatenates the strings in the list, + using the provided separator, without relying on str.join(). - Examples: - - >>> join("", ["a", "b", "c", "d"]) - 'abcd' - >>> join("#", ["a", "b", "c", "d"]) - 'a#b#c#d' - >>> join("#", ["a"]) - 'a' - >>> join(" ", ["You", "are", "amazing!"]) - 'You are amazing!' - - This example should raise an exception for non-string elements: - >>> join("#", ["a", "b", "c", 1]) - Traceback (most recent call last): - ... - Exception: join() accepts only strings - - Additional test case with a different separator: - >>> join("-", ["apple", "banana", "cherry"]) - 'apple-banana-cherry' - >>> join(",", ["", "", ""]) - ',,,' # This test will now pass correctly + :param separator: The separator to place between strings. + :param separated: A list of strings to join. + :return: A single string with elements joined by the separator. + + :raises Exception: If any element in the list is not a string. """ - if not all(isinstance(word_or_phrase, str) for word_or_phrase in separated): raise Exception("join() accepts only strings") - joined = separator.join(separated) + # Manually handle concatenation + result = "" + for i, element in enumerate(separated): + result += element + if i < len(separated) - 1: # Add separator only between elements + result += separator - return joined + return result if __name__ == "__main__": From ae09865ee8fbf7d6de165dfe6fd9214498073121 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 05:39:36 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/join.py b/strings/join.py index a60b8fbb30ab..d35ce68baf86 100644 --- a/strings/join.py +++ b/strings/join.py @@ -8,7 +8,7 @@ def join(separator: str, separated: list[str]) -> str: :param separated: A list of strings to join. :return: A single string with elements joined by the separator. - + :raises Exception: If any element in the list is not a string. """ if not all(isinstance(word_or_phrase, str) for word_or_phrase in separated): From fb63afef2ed979abc90c640c3e1609cd27572b0a Mon Sep 17 00:00:00 2001 From: Sankalpa Sarkar <137193167+sanks011@users.noreply.github.com> Date: Thu, 19 Dec 2024 11:24:17 +0530 Subject: [PATCH 08/12] updated join.py --- strings/join.py | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/strings/join.py b/strings/join.py index d35ce68baf86..8550b956a4a8 100644 --- a/strings/join.py +++ b/strings/join.py @@ -10,15 +10,37 @@ def join(separator: str, separated: list[str]) -> str: :return: A single string with elements joined by the separator. :raises Exception: If any element in the list is not a string. - """ - if not all(isinstance(word_or_phrase, str) for word_or_phrase in separated): - raise Exception("join() accepts only strings") - # Manually handle concatenation + Examples: + >>> join("", ["a", "b", "c", "d"]) + 'abcd' + >>> join("#", ["a", "b", "c", "d"]) + 'a#b#c#d' + >>> join("#", "a") # Single string instead of list + Traceback (most recent call last): + ... + Exception: join() accepts only strings + >>> join(" ", ["You", "are", "amazing!"]) + 'You are amazing!' + >>> join("#", ["a", "b", "c", 1]) + Traceback (most recent call last): + ... + Exception: join() accepts only strings + >>> join("-", ["apple", "banana", "cherry"]) + 'apple-banana-cherry' + >>> join(",", ["", "", ""]) + ',,' + """ result = "" - for i, element in enumerate(separated): - result += element - if i < len(separated) - 1: # Add separator only between elements + for i, word_or_phrase in enumerate(separated): + # Check if the element is a string + if not isinstance(word_or_phrase, str): + raise Exception("join() accepts only strings") + + # Add the current word or phrase to the result + result += word_or_phrase + # Add the separator if it's not the last element + if i < len(separated) - 1: result += separator return result From b9d9cb38a70f7a8fc6c0c3c782ff67c0f21dddb8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 05:56:44 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/join.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/join.py b/strings/join.py index 8550b956a4a8..b1da249aeaeb 100644 --- a/strings/join.py +++ b/strings/join.py @@ -36,7 +36,7 @@ def join(separator: str, separated: list[str]) -> str: # Check if the element is a string if not isinstance(word_or_phrase, str): raise Exception("join() accepts only strings") - + # Add the current word or phrase to the result result += word_or_phrase # Add the separator if it's not the last element From 245fb36449413e99de8a9cc87f01ff12171ba651 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sun, 29 Dec 2024 15:05:41 +0300 Subject: [PATCH 10/12] Update split.py --- strings/split.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/strings/split.py b/strings/split.py index fc7965aea8d4..ed194ec69c2f 100644 --- a/strings/split.py +++ b/strings/split.py @@ -20,13 +20,11 @@ def split(string: str, separator: str = " ") -> list: """ split_words = [] - last_index = 0 + last_index = 0 for index, char in enumerate(string): if char == separator: - split_words.append( - string[last_index:index] - ) # Add substring between separators + split_words.append(string[last_index:index]) last_index = index + 1 if index + 1 == len(string): split_words.append(string[last_index : index + 1]) From 4ef69c8ff6ff38e1d6f65f001aebdf5e56df740a Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sun, 29 Dec 2024 16:45:07 +0300 Subject: [PATCH 11/12] Update join.py --- strings/join.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/strings/join.py b/strings/join.py index b2d7416cd8da..89c5a04a3ece 100644 --- a/strings/join.py +++ b/strings/join.py @@ -1,17 +1,21 @@ +""" +Program to join a list of strings with a separator +""" + + def join(separator: str, separated: list[str]) -> str: """ - Custom implementation of the join() function. - This function manually concatenates the strings in the list, - using the provided separator, without relying on str.join(). + Joins a list of strings using a separator + and returns the result. - :param separator: The separator to place between strings. - :param separated: A list of strings to join. + :param separator: Separator to be used + for joining the strings. + :param separated: List of strings to be joined. - :return: A single string with elements joined by the separator. - - :raises Exception: If any element in the list is not a string. + :return: Joined string with the specified separator. Examples: + >>> join("", ["a", "b", "c", "d"]) 'abcd' >>> join("#", ["a", "b", "c", "d"]) From e60c15ff3977e8ce935fd2a75fcf6ce2115b8c0a Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sun, 29 Dec 2024 16:47:00 +0300 Subject: [PATCH 12/12] Update join.py --- strings/join.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/strings/join.py b/strings/join.py index 89c5a04a3ece..cdcc3a1377f4 100644 --- a/strings/join.py +++ b/strings/join.py @@ -20,10 +20,8 @@ def join(separator: str, separated: list[str]) -> str: 'abcd' >>> join("#", ["a", "b", "c", "d"]) 'a#b#c#d' - >>> join("#", "a") # Single string instead of list - Traceback (most recent call last): - ... - Exception: join() accepts only strings + >>> join("#", "a") + 'a' >>> join(" ", ["You", "are", "amazing!"]) 'You are amazing!' >>> join(",", ["", "", ""]) @@ -35,10 +33,10 @@ def join(separator: str, separated: list[str]) -> str: Traceback (most recent call last): ... Exception: join() accepts only strings + + Additional test case with a different separator: >>> join("-", ["apple", "banana", "cherry"]) 'apple-banana-cherry' - >>> join(",", ["", "", ""]) - ',,' """ # Check that all elements are strings