首页 > 其他 > 详细

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

时间:2020-04-05 23:20:22      阅读:127      评论:0      收藏:0      [点我收藏+]

题目描述:

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

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

原文:https://www.cnblogs.com/wlj-axia/p/12639433.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!