Skip to content

Commit 6729904

Browse files
committed
case
1 parent c17e03e commit 6729904

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

exam1/cases.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,24 @@
1313
variable in camel case and outputs the corresponding name in snake case.
1414
Assume that the user’s input will indeed be in camel case.
1515
'''
16-
16+
def camel2snake(word:str):
17+
result=''
18+
for char in word:
19+
if char.isupper():
20+
result += "_"+char.lower()
21+
else:
22+
result +=char
23+
return result
1724

1825
'''
1926
Now make one that does the opposite: snake2camel()
2027
'''
21-
28+
def snake2camel(word:str):
29+
lst=word.split('_')
30+
result=lst[0]
31+
for i in range(1,len(lst)):
32+
result+=lst[i].capitalize()
33+
return result
2234

2335
def foo():
2436
pass

0 commit comments

Comments
 (0)