
정답 코드
import sys
input = sys.stdin.readline
n = int(input())
coordinates = [list(map(int, input().split())) for _ in range(n)]
coordinates = sorted(coordinates)
for c in coordinates :
x, y = c
print(x, y)
람다를 이용하여 2차원 배열 정렬하기
만약 y → x 좌표를 기준으로 정렬하는 문제였다면?
coordinates.sort(key = lamdba x : (x[1], x[0]))
'코딩 테스트 > 백준' 카테고리의 다른 글
[Python] 백준 17266 어두운 굴다리 (2) | 2025.02.11 |
---|---|
[Python] 백준 15686 치킨 배달 (0) | 2025.02.11 |
[Python] 백준 3040 백설 공주와 일곱 난쟁이 (0) | 2025.02.11 |
[Python] 백준 10989 수 정렬하기 3 (0) | 2025.02.10 |
[Python] 백준 10974 모든 순열 (0) | 2025.02.10 |