Convert string to camel case
- Complete the method/function so that it converts dash/underscore Delimited words into camel casing.
- The first word within the output should be capitalized only if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case).
Examples:
"the-stealth-warrior" gets converted -> "theStealthWarrior"
"The_Stealth_Warrior" gets converted -> "TheStealthWarrior"
Task URL: Link
My Solution:
def to_camel_case(text):
if len(text) > 1:
if not text[0].isupper():
case_one = ''.join(x for x in text.title() if x.isalnum())
return case_one[0].lower() + case_one[1:]
elif text[0].isupper():
case_tow = ''.join(x for x in text.title() if x.isalnum())
return case_tow
else:
return ''
Code Snapshot:
Learn Python
Python top free courses from Courseraππ―π
π₯
Top comments (2)
same but much more simple
This does not work as expected, but this does:
output: