노력에는 지름길이 없으니까요

프로그래머스 - 점의 위치 구하기 Python ver. 본문

Python/프로그래머스

프로그래머스 - 점의 위치 구하기 Python ver.

데건 2024. 7. 9. 11:19
728x90

 

해결일 언어 레벨 테스트명
20240617 Python level 0  점의 위치 구하기

 

링크 : https://school.programmers.co.kr/learn/courses/30/lessons/120841

 

 


 

내 코드

def solution(dot):
    return (2 if dot[0]<0 else 4) if dot[0]*dot[1]<0 else (3 if dot[0]<0 else 1)

 

 

 

개선점: if를 덜 써보고 싶었는데 다른 방법은 생각이 안났음 ㅋㅋ

 

베스트 코드

def solution(dot):
    quad = [(3,2),(4,1)]
    return quad[dot[0] > 0][dot[1] > 0]

 

 

 

728x90
반응형