Example:
HILO -> Hilo
new york -> New York
SAN FRANCISCO -> San Francisco
Is there a library or standard way to perform this task?
Definition and UsageThe title() method returns a string where the first character in every word is upper case. Like a header, or a title. If the word contains a number or a symbol, the first letter after that will be converted to upper case.
string => string. toLowerCase().
The title() method returns a string with first letter of each word capitalized; a title cased string.
The capitalize() method returns a string where the first character is upper case, and the rest is lower case.
Why not use title
Right from the docs:
>>> "they're bill's friends from the UK".title()
"They'Re Bill'S Friends From The Uk"
If you really wanted PascalCase you can use this:
>>> ''.join(x for x in 'make IT pascal CaSe'.title() if not x.isspace())
'MakeItPascalCase'
This one would always start with lowercase, and also strip non alphanumeric characters:
def camelCase(st):
output = ''.join(x for x in st.title() if x.isalnum())
return output[0].lower() + output[1:]
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