We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 791deb4 commit d403e35Copy full SHA for d403e35
1 file changed
strings/split.py
@@ -20,14 +20,16 @@ def split(string: str, separator: str = " ") -> list:
20
"""
21
22
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)
32
- 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])
33
return split_words
34
35
0 commit comments