Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions strings/split.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def split(string: str, separator: str = " ") -> list:

>>> split("12:43:39",separator = ":")
['12', '43', '39']

>>> split(";abbb;;c;", separator=';')
['', 'abbb', '', 'c', '']
"""

split_words = []
Expand All @@ -25,6 +28,9 @@ def split(string: str, separator: str = " ") -> list:
last_index = index + 1
elif index + 1 == len(string):
split_words.append(string[last_index : index + 1])

# Append the last segment, including cases where the string ends with the separator
split_words.append(string[last_index:])
return split_words


Expand Down
Loading