📝 문제
✔️ 나의 풀이
def solution(numLog):
num = numLog[0]
result = ""
for i in range(1, len(numLog)):
diff = numLog[i] - numLog[i-1]
if diff == 1:
result += "w"
elif diff == -1:
result += "s"
elif diff == 10:
result += "d"
elif diff == -10:
result += "a"
return result
🔎 다른 사람의 풀이
def solution(log):
res=''
joystick=dict(zip([1,-1,10,-10],['w','s','d','a']))
for i in range(1,len(log)):
res+=joystick[log[i]-log[i-1]]
return res
✏️ 배운점
zip을 이용하여 입력값과 출력값을 짝지어 dict로 묶어서 코드 작성시 조금 더 간결하고 직관적으로 작성할 수 있었다.
반응형
'Codingtest' 카테고리의 다른 글
[프로그래머스][파이썬] #06. 배열 만들기 4 (0) | 2023.07.24 |
---|---|
[프로그래머스][파이썬] #05. 수열과 구간 쿼리 2 (0) | 2023.07.21 |
[프로그래머스][파이썬] #03. 등차수열의 특정한 항만 더하기 (0) | 2023.07.19 |
[프로그래머스][파이썬] #02. 특수문자 출력하기 (0) | 2023.07.17 |
[프로그래머스][파이썬] #01. 대소문자 바꿔서 출력하기 (0) | 2023.07.17 |