mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 00:07:00 +00:00
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:
parent
2b58ab0402
commit
2d68bb50e5
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user