-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamelCasing_v2.py
More file actions
58 lines (49 loc) · 1.99 KB
/
camelCasing_v2.py
File metadata and controls
58 lines (49 loc) · 1.99 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
def split_by_capitals(capital_string):
variable = capital_string
index_of_capitals = [variable.index(letter) for letter in variable if letter.isupper()]
result = ''
prev_idx = 0
for curr_idx in index_of_capitals:
if curr_idx>0:
result += ' ' + variable[prev_idx:curr_idx].lower()
prev_idx = curr_idx
if curr_idx == index_of_capitals[-1]:
result += ' ' + variable[curr_idx:].lower()
return result.strip()
def camelCasing(code):
if code[0] == 'S':
if code[1] in ['V', 'C']:
#S;V;pictureFrame -> picture frame
#S;C;LargeSoftwareBook -> large software book
result_str = split_by_capitals(code[2])
return result_str
else: #M
#S;M;plasticCup() -> plastic cup
result_str = split_by_capitals(code[2])
return result_str[:-2]
elif code[0] == 'C':
if code[1] == 'V':
#C;V;mobile phone -> mobilePhone
strings = code[2].split(' ')
result_str = strings[0]+ ''.join([s.capitalize() for s in strings[1:]])
return result_str
elif code[1] == 'C':
#C;C;coffee machine -> CoffeeMachine
strings_arr = [s.capitalize() for s in code[2].split(' ')]
return ''.join(strings_arr)
else: #M
#C;M;white sheet of paper -> whiteSheetOfPaper()
strings = code[2].split(' ')
result_str = strings[0]+ ''.join([s.capitalize() for s in strings[1:]])
return result_str+'()'
return 'Format not supported'
if __name__ == '__main__':
strings = sys.stdin.readlines()
for code_line in strings:
code = list(code_line.strip().split(';'))
#[0] =S|M
#[1] = V|C|M
#[2] = variable|Class|Method()
result = camelCasing(code)
print(result)