문제/백준_파이썬
88. 10814(나이순 정렬)
sm_hope
2022. 6. 17. 10:43
import sys
input = sys.stdin.readline
N = int(input())
personList = []
for _ in range(N):
age, name = input().split()
age = int(age)
personList.append([age, name])
sortedPerson = sorted(personList, key=lambda x: (x[0]))
for valAge, valName in sortedPerson:
print(str(valAge)+" "+valName)
문제 요약
나이순으로 정렬하고 나이가 같다면 입력순으로 정렬하시오.
설명
리스트는 여러가지 형태의 값들을 한번에 저장이 가능하다.
따라서 나이는 int형으로, 이름은 string형으로 처리할 수 있는지, 정렬을 올바르게 사용할 수 있는지에 대해 묻는 문제이다.
https://smhope.tistory.com/222?category=1052318
sort()와 sorted()
sort 함수 리스트명.sort(옵션) # reverse = True (내림차순) 리스트의 원본값을 직접 수정한다. 만약 a1 = [7, 1, 5] print('a1:', a1) a2 = a1.sort() print('a1:', a1) print('a2:', a2) 의 출력 결과는 a1: [7..
smhope.tistory.com