Skip to content

Conversation

Miladkhoshdel
Copy link
Contributor

Changes:

  • Removed dependency on string.ascii_lowercase and string.ascii_uppercase and Replaced string-based capitalization with manual ASCII offset
  • Reduced function complexity and branching
  • Added basic unit tests to ensure correctness

Benefits:

  • Eliminated external module dependency (string) for better portability and reduced overhead
  • Improved performance (5× faster in benchmarks)
  • More efficient implementation
  • Maintains readability and correctness

Checklist:

  • Code compiles without errors
  • Performance verified with benchmarks

@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Aug 24, 2025
@MaximSmolskiy MaximSmolskiy changed the title Simplify Capitalize Function Using ASCII Arithmetic for 5x Performance Boost Simplify Capitalize Function Aug 24, 2025
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Aug 24, 2025
@MaximSmolskiy MaximSmolskiy merged commit a8c5616 into TheAlgorithms:master Aug 24, 2025
5 checks passed
cclauss pushed a commit to cclauss/Python that referenced this pull request Aug 25, 2025
* Simplify the capitalize function using ASCII arithmetic to make the algorithm five times faster.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update capitalize.py

* Update capitalize.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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants