I'm looking for a library that properly capitalizes a given string by assuming it is a title. I know there is string.title(), but it capitalizes every work, not just the one's that should be capitalized. Anyone know any libraries?
Examples of words that should not be capitalized in titles:
To make titlecased version of a string, you use the string title() method. The title() returns a copy of a string in the titlecase. The title() method converts the first character of each words to uppercase and the remaining characters in lowercase.
The capitalize() method returns a string where the first character is upper case, and the rest is lower case.
True and False in Python are capitialised because they are constants and it is common practice to capitialise constants in Python. Other languages with similar naming practices tend not to follow it for whatever reason. The language is also case sensitive meaning true and True are different according to Python.
To capitalize the first letter, use the capitalize() function. This functions converts the first character to uppercase and converts the remaining characters to lowercase.
The term to Google for is "titlecase". The first hit is the titlecase
package:
$ pip install titlecase
...
$ python
...
>>> from titlecase import titlecase
>>> titlecase('the spam and eggs')
'The Spam and Eggs'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With