Skip to content

Commit d403e35

Browse files
committed
Issue #14649
1 parent 791deb4 commit d403e35

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

strings/split.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ def split(string: str, separator: str = " ") -> list:
2020
"""
2121

2222
split_words = []
23+
start = 0
24+
25+
while True:
26+
index = string.find(separator, start)
27+
if index == -1:
28+
split_words.append(string[start:])
29+
break
30+
split_words.append(string[start:index])
31+
start = index + len(separator)
2332

24-
last_index = 0
25-
for index, char in enumerate(string):
26-
if char == separator:
27-
split_words.append(string[last_index:index])
28-
last_index = index + 1
29-
if index + 1 == len(string):
30-
split_words.append(string[last_index : index + 1])
3133
return split_words
3234

3335

0 commit comments

Comments
 (0)