Skip to content

Fix split multi character separator#14721

Open
miaomiao0319 wants to merge 2 commits into
TheAlgorithms:masterfrom
miaomiao0319:fix-split-multi-character-separator
Open

Fix split multi character separator#14721
miaomiao0319 wants to merge 2 commits into
TheAlgorithms:masterfrom
miaomiao0319:fix-split-multi-character-separator

Conversation

@miaomiao0319
Copy link
Copy Markdown

@miaomiao0319 miaomiao0319 commented May 26, 2026

Describe your change:

This PR fixes #14649 by validating invalid separators in strings/split.py.

Changes:

  • Add validation for empty separators.
  • Add validation for multi-character separators.
  • Add doctest examples for invalid separators.
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Copilot AI review requested due to automatic review settings May 26, 2026 04:52
@algorithms-keeper algorithms-keeper Bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels May 26, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR tightens validation for the separator argument in split() and updates the docstring examples to reflect the new behavior.

Changes:

  • Added input validation to reject empty separators and multi-character separators
  • Updated doctest examples for formatting consistency and to include new error cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread strings/split.py
Comment on lines 3 to 4
Will split the string up into all the values separated by the separator
(defaults to spaces)
Comment thread strings/split.py
Comment on lines +32 to +36
if not separator:
raise ValueError("separator should not be empty")

if len(separator) != 1:
raise ValueError("separator should be a single character")
Copy link
Copy Markdown

@diusazzad diusazzad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, you are raising a ValueError if len(separator) != 1. But typically, a split function should be able to handle multi character separators

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

split silently returns wrong result for multi-character separators

3 participants