@@ -3,17 +3,20 @@ def split(string: str, separator: str = " ") -> list:
33 Will split the string up into all the values separated by the separator
44 (defaults to spaces)
55
6- >>> split("apple#banana#cherry#orange",separator='#')
6+ # >>> split("apple#banana#cherry#orange",separator='#')
77 ['apple', 'banana', 'cherry', 'orange']
88
9- >>> split("Hello there")
9+ # >>> split("Hello there")
1010 ['Hello', 'there']
1111
12- >>> split("11/22/63",separator = '/')
12+ # >>> split("11/22/63",separator = '/')
1313 ['11', '22', '63']
1414
15- >>> split("12:43:39",separator = ":")
15+ # >>> split("12:43:39",separator = ":")
1616 ['12', '43', '39']
17+
18+ # >>> split(";abbb;;c;", separator=';')
19+ ['', 'abbb', '', 'c', '']
1720 """
1821
1922 split_words = []
@@ -25,6 +28,9 @@ def split(string: str, separator: str = " ") -> list:
2528 last_index = index + 1
2629 elif index + 1 == len (string ):
2730 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 :])
2834 return split_words
2935
3036
0 commit comments