DESCRIPTION:
Complete the function/method so that it takes a PascalCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If the method gets a number as input, it should return a string.
Examples
"TestController" --> "test_controller"
"MoviesAndBooks" --> "movies_and_books"
"App7Test" --> "app7_test"
1 --> "1"
def to_underscore(s):
s=str(s)
ans=""
for i in s:
if i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
ans+="_"
ans+=i.lower()
else:
ans+=i
if ans[0]=="_":
return ans[1:]
return ans
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
Two Joggers (0) | 2022.10.31 |
---|---|
Where is my parent!?(cry) (0) | 2022.10.29 |
Grouped by commas (0) | 2022.10.29 |
Pair of gloves (0) | 2022.10.29 |
English Beggars (0) | 2022.10.28 |