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>
This commit is contained in:
KICH Yassine 2024-12-29 12:56:36 +01:00 committed by GitHub
parent 2b58ab0402
commit 2d68bb50e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 = []
@ -23,7 +26,7 @@ def split(string: str, separator: str = " ") -> list:
if char == separator:
split_words.append(string[last_index:index])
last_index = index + 1
elif index + 1 == len(string):
if index + 1 == len(string):
split_words.append(string[last_index : index + 1])
return split_words