51일차 문제

양진혁·2021년 12월 22일
0

문제풀이

The main idea is to count all the occurring characters in a string. If you have a string like aba, then the result should be {'a': 2, 'b': 1}.

def count(string):
  count = {}
  for i in string:
    try: count[i] += 1
    except: count[i]=1
  return count

try except문을 사용해서 문제를 해결하였다.

두번째는
camelcase("hello case") => HelloCase
camelcase("camel case word") => CamelCaseWord

def camel_case(string):
  return string.title().replace( " ","")

파이썬의 title과 replace를 사용해서 앞글자를 대문자로 만든 후 띄어쓰기를 제거했다.

0개의 댓글