完成方法/函数,以便将破折号/下划线分隔的单词转换为驼峰式大小写

题目描述:

# 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)

posted on 2020-04-05 22:06  阿虾  阅读(383)  评论(0编辑  收藏  举报

导航