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("_","")
2 odpowiedzi
+ 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 :)
+ 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.