TEAMLAB-Lecture / python-101-for-data-science-by-pknu

1 stars 14 forks source link

text_processing2 두번째 문제에 관한 질문 #16

Closed 54162476 closed 2 years ago

54162476 commented 2 years ago
def to_camel_case(underscore_str):

camelcase_str = ""
if '_' not in underscore_str:
    camelcase_str = underscore_str[0].lower() + underscore_str[1:]
elif only '_' in underscore_str:
    camelcase_str = underscore_str.replace('_','')
else :
    i = underscore_str.title().replace('_','')
    camelcase_str = i[0].lower() + i[1:]
return  camelcase_str

교수님 코드 작동이 잘 되지 않습니다. 어느 부분이 잘못된건지 모르겠습니다.

blissray commented 2 years ago

elif only '_' in underscore_str: 이런 문법은 없습니다.

54162476 commented 2 years ago

'_'만 있을 경우 코드를 어떤식으로 짜야하는지 모르겠습니다.

54162476 commented 2 years ago
def to_camel_case(underscore_str):
    camelcase_str = ""
    if '_' not in underscore_str:
        camelcase_str = underscore_str[0].lower() + underscore_str[1:]
    elif '_' == underscore_str:
        camelcase_str = underscore_str.replace('_','')
    else:   
        i = underscore_str.title().replace('_','')
        camelcase_str = i[0].lower() + i[1:]
    return camelcase_str

교수님 '_' == underscore_str 이건 문자열에 _만 있다는 뜻이 아닌가요?

blissray commented 2 years ago

음 아니에요 여러개있을수있잖아요?