▶ 문제 :
▶ 내 답안 :
def square_digits(num):
return int(''.join([ str(int(i)**2) for i in str(num) ]))
▶ 모범답안 :
def square_digits(num) :
ret = ""
for x in str(num) :
ret += str(int(x)**2)
return int(ret)
▶ 배워야할 부분 : 가독성이 좋은 코드 > 짧은 코드
'데이터 - 기본 코드 및 알고리즘 연습 > Codewar' 카테고리의 다른 글
[Codewars] Sine, cosine and others (0) | 2021.06.30 |
---|---|
[Codewars] Double Every Other (0) | 2021.06.30 |
[Codewars] Connect Four (0) | 2021.06.28 |
[Codewars] Product of consecutive Fib numbers (0) | 2021.06.25 |
[Codewars] Kebabize (0) | 2021.06.23 |