@@ -3,17 +3,20 @@ def split(string: str, separator: str = " ") -> list:
3
3
Will split the string up into all the values separated by the separator
4
4
(defaults to spaces)
5
5
6
- >>> split("apple#banana#cherry#orange",separator='#')
6
+ # >>> split("apple#banana#cherry#orange",separator='#')
7
7
['apple', 'banana', 'cherry', 'orange']
8
8
9
- >>> split("Hello there")
9
+ # >>> split("Hello there")
10
10
['Hello', 'there']
11
11
12
- >>> split("11/22/63",separator = '/')
12
+ # >>> split("11/22/63",separator = '/')
13
13
['11', '22', '63']
14
14
15
- >>> split("12:43:39",separator = ":")
15
+ # >>> split("12:43:39",separator = ":")
16
16
['12', '43', '39']
17
+
18
+ # >>> split(";abbb;;c;", separator=';')
19
+ ['', 'abbb', '', 'c', '']
17
20
"""
18
21
19
22
split_words = []
@@ -25,6 +28,9 @@ def split(string: str, separator: str = " ") -> list:
25
28
last_index = index + 1
26
29
elif index + 1 == len (string ):
27
30
split_words .append (string [last_index : index + 1 ])
31
+
32
+ # Append the last segment, including cases where the string ends with the separator
33
+ split_words .append (string [last_index :])
28
34
return split_words
29
35
30
36
0 commit comments