From d403e35d7a29c77d91a1e11b3490ccc1a9f0d10e Mon Sep 17 00:00:00 2001 From: Rishon Pravin Date: Tue, 12 May 2026 16:58:20 +0530 Subject: [PATCH] Issue #14649 --- strings/split.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/strings/split.py b/strings/split.py index ed194ec69c2f..7aff9cb2fe70 100644 --- a/strings/split.py +++ b/strings/split.py @@ -20,14 +20,16 @@ def split(string: str, separator: str = " ") -> list: """ split_words = [] + start = 0 + + while True: + index = string.find(separator, start) + if index == -1: + split_words.append(string[start:]) + break + split_words.append(string[start:index]) + start = index + len(separator) - last_index = 0 - for index, char in enumerate(string): - if char == separator: - split_words.append(string[last_index:index]) - last_index = index + 1 - if index + 1 == len(string): - split_words.append(string[last_index : index + 1]) return split_words