Anyone help me with this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Anyone help me with this?

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 to "theStealthWarrior" "The_Stealth_Warrior" gets converted to "TheStealthWarrior" And here's my try: def to_camel_case(text): r = text.count("-") if r>0: return text.replace("-","") else: return text.replace("_","")

5th Jan 2022, 1:41 AM
Ravi King
2 Answers
+ 4
you are almost there, all thats missing is the capital letters after a - or _ I would probably approach this differently. Try looping over every characters, if the character is a - or _, then remove it and capitalize the character thats next to it. I hope this will help :)
5th Jan 2022, 2:06 AM
Apollo-Roboto
Apollo-Roboto - avatar
+ 1
Also, the count ("-") stuff is unnecessary. You can just replace dashes and underscores as they appear. This adds the ability to deal with words containing both chars. As for the first word casing, maybe just skipping first char does it. BTW, try to code in code playground and, when stuck or finished, link it with + button inside the question, so we can see, test and help if needed.
5th Jan 2022, 2:33 AM
Emerson Prado
Emerson Prado - avatar