Python
Python copied to clipboard
Improve capitalize(): add Unicode support and handle leading spaces
Summary:
This Pull Request improves the existing capitalize() function by making it more robust and user-friendly. The function now properly capitalises the first alphabetical character, handles Unicode letters, and preserves leading spaces — all while maintaining backward compatibility.
Changes Introduced:
Added logic to locate the first alphabetic character (not just index 0).
Added support for Unicode characters such as ñ, ö, ç, etc.
Preserved the original structure of the string, including leading spaces.
Improved and expanded doctest examples for better coverage.
I'd like for you to ensure safe handling of empty strings and strings without alphabetic characters.