题目描述:
# 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
# to_camel_case("the-stealth-warrior") # returns "theStealthWarrior"
#
# to_camel_case("The_Stealth_Warrior") # returns "TheStealthWarrior"
我的解答:
def to_camel_case(s):
new_s = s.replace("-", "_")
a = new_s.split("_")
for i in range(1, len(a)):
a[i] = a[i].capitalize()
return ''.join(a)