From 3b1b70bf0e60dddb14917dd7cad34a41d429df01 Mon Sep 17 00:00:00 2001 From: usman Date: Tue, 3 Dec 2024 03:07:05 +0500 Subject: [PATCH 1/2] Fix the separator issue --- strings/split.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/strings/split.py b/strings/split.py index b62b86d2401f..20ce671c8162 100644 --- a/strings/split.py +++ b/strings/split.py @@ -3,17 +3,20 @@ 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") + # >>> 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=';') + ['', 'abbb', '', 'c', ''] """ split_words = [] @@ -25,6 +28,9 @@ def split(string: str, separator: str = " ") -> list: last_index = index + 1 elif index + 1 == len(string): split_words.append(string[last_index : index + 1]) + + # Append the last segment, including cases where the string ends with the separator + split_words.append(string[last_index:]) return split_words From 5c3562f8dd3e0df8f12cfa27bf19ab5cb13d82a8 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sun, 29 Dec 2024 14:40:13 +0300 Subject: [PATCH 2/2] Update split.py --- strings/split.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/strings/split.py b/strings/split.py index 20ce671c8162..b8b5b8429174 100644 --- a/strings/split.py +++ b/strings/split.py @@ -3,19 +3,19 @@ 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") + >>> 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', ''] """