Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2d68bb5

Browse files
kishyassinpre-commit-ci[bot]MaximSmolskiy
authored
Fix split function to handle trailing delimiters correctly (#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 <mithridatus@mail.ru>
1 parent 2b58ab0 commit 2d68bb5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

‎strings/split.py

Lines changed: 4 additions & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /