diff --git a/strings/split.py b/strings/split.py index b62b86d2401f..b8b5b8429174 100644 --- a/strings/split.py +++ b/strings/split.py @@ -14,6 +14,9 @@ def split(string: str, separator: str = " ") -> list: >>> 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