알고리즘/코드워
[python]CamelCase Method
(ㅇㅅㅎ)
2020. 3. 15. 13:31
728x90
반응형
https://www.codewars.com/kata/587731fda577b3d1b0001196/train/python
Codewars: Train your coding skills
Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.
www.codewars.com
문자열에서 각 단어들의 맨 알파벳을 대문자로 변경 후 스페이스 없애는 문제이다.
더보기

title()이라는 것을 사용하면 각 단어의 첫 글자를 대문자로 변경해준다.
replace("old", "new")라는 것을 사용하면 old를 new로 바꾸어준다.
이 두 가지를 혼합해서 코드를 작성하였다.
내 코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# My Code
def camel_case(string):
return string.title().replace(" ", "")
if __name__=='__main__':
answer = camel_case("test case")
print(answer)
answer = camel_case("camel case method")
print(answer)
answer = camel_case("say hello ")
print(answer)
answer = camel_case(" camel case word")
print(answer)
answer = camel_case("")
print(answer)
|

반응형