-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertStringToCamelCase.py
More file actions
42 lines (31 loc) · 1.19 KB
/
ConvertStringToCamelCase.py
File metadata and controls
42 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Convert string to camel case
# 5kyu
# https://www.codewars.com/kata/convert-string-to-camel-case/python
'''
Description:
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.
Examples:
# returns "theStealthWarrior"
to_camel_case("the-stealth-warrior")
# returns "TheStealthWarrior"
to_camel_case("The_Stealth_Warrior")
'''
def to_camel_case(text):
if text == '':
return ''
else:
camel_case = text[0]
for i in range(1, len(text)):
if text[i] == '-' or text[i] == '_':
pass
elif text[i - 1] == '-' or text[i - 1] == '_':
camel_case += text[i].upper()
else:
camel_case += text[i]
return camel_case
def to_camel_case(text):
return text[0] + ''.join([w[0].upper() + w[1:]
for w in text.replace("_", "-").split("-")])[1:] if text else ''
def to_camel_case(text):
return text[0] + ''.join([w[0].upper() + w[1:]
for w in text.replace("_", "-").split("-")])[1:] if text else ''