From 12c7ce2816df5b3329b70316f6b5ded674357a54 Mon Sep 17 00:00:00 2001 From: cao-yuchang <3880133236@qq.com> Date: Tue, 26 May 2026 12:21:39 +0800 Subject: [PATCH 1/2] Fix split validation for invalid separators --- strings/split.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/strings/split.py b/strings/split.py index ed194ec69c2f..9ffd96a2b4f2 100644 --- a/strings/split.py +++ b/strings/split.py @@ -3,22 +3,38 @@ def split(string: str, separator: str = " ") -> list: Will split the string up into all the values separated by the separator (defaults to spaces) - >>> split("apple#banana#cherry#orange",separator='#') + >>> split("apple#banana#cherry#orange", separator="#") ['apple', 'banana', 'cherry', 'orange'] >>> split("Hello there") ['Hello', 'there'] - >>> split("11/22/63",separator = '/') + >>> split("11/22/63", separator="/") ['11', '22', '63'] - >>> split("12:43:39",separator = ":") + >>> split("12:43:39", separator=":") ['12', '43', '39'] - >>> split(";abbb;;c;", separator=';') + >>> split(";abbb;;c;", separator=";") ['', 'abbb', '', 'c', ''] + + >>> split("apple--banana--cherry", separator="--") + Traceback (most recent call last): + ... + ValueError: separator should be a single character + + >>> split("apple", separator="") + Traceback (most recent call last): + ... + ValueError: separator should not be empty """ + if not separator: + raise ValueError("separator should not be empty") + + if len(separator) != 1: + raise ValueError("separator should be a single character") + split_words = [] last_index = 0 @@ -34,4 +50,4 @@ def split(string: str, separator: str = " ") -> list: if __name__ == "__main__": from doctest import testmod - testmod() + testmod() \ No newline at end of file From 2d51566a7f39b08e873f816259242c80f9d45fc7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 May 2026 04:25:36 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/split.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/split.py b/strings/split.py index 9ffd96a2b4f2..2ee6d97c12d4 100644 --- a/strings/split.py +++ b/strings/split.py @@ -50,4 +50,4 @@ def split(string: str, separator: str = " ") -> list: if __name__ == "__main__": from doctest import testmod - testmod() \ No newline at end of file + testmod()