물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Converting string to camel case

BEstyle 2022. 10. 26. 13:10

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 (known as Upper Camel Case, also often referred to as Pascal case).

Examples

"the-stealth-warrior" gets converted to "theStealthWarrior"
"The_Stealth_Warrior" gets converted to "TheStealthWarrior"


def to_camel_case(text):
    text=text.replace("_","@").replace("-","@")
    print(text.capitalize())
    alist=text.split("@")
    ans=alist[0]
    for i in alist[1:]:
        if len(i)>=2:
            ans+=i.capitalize()
        else:
            ans+=i
    return ans

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Sum consecutives  (0) 2022.10.28
The Deaf Rats of Hamelin  (0) 2022.10.28
Counting Duplicates  (0) 2022.10.26
Human readable duration format  (0) 2022.10.26
New Cashier Does Not Know About Space or Shift  (0) 2022.10.25