Skip to content
Merged
Changes from 1 commit
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
Next Next commit
Fix split function to handle trailing delimiters correctly (TheAlgori…
…thms#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>
  • Loading branch information
3 people authored Dec 29, 2024
commit 2d68bb50e5f12532b5a0d616305c4f805d2b8ff9
5 changes: 4 additions & 1 deletion 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 @@ -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

Expand Down