Skip to content

Commit 2d68bb5

Browse files
kishyassinpre-commit-ci[bot]MaximSmolskiy
authored
Fix split function to handle trailing delimiters correctly (TheAlgorithms#12423)
* Fix split function to handle trailing delimiters correctly * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update split.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Maxim Smolskiy <[email protected]>
1 parent 2b58ab0 commit 2d68bb5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

strings/split.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def split(string: str, separator: str = " ") -> list:
1414
1515
>>> split("12:43:39",separator = ":")
1616
['12', '43', '39']
17+
18+
>>> split(";abbb;;c;", separator=';')
19+
['', 'abbb', '', 'c', '']
1720
"""
1821

1922
split_words = []
@@ -23,7 +26,7 @@ def split(string: str, separator: str = " ") -> list:
2326
if char == separator:
2427
split_words.append(string[last_index:index])
2528
last_index = index + 1
26-
elif index + 1 == len(string):
29+
if index + 1 == len(string):
2730
split_words.append(string[last_index : index + 1])
2831
return split_words
2932

0 commit comments

Comments
 (0)