파이썬 알고리즘 200번 | [백준 11651번] 단어정렬2 - lambda 로 특정 키 sort, filter

Yunny.Log ·2022년 7월 11일
0

Algorithm

목록 보기
203/318
post-thumbnail

200.단어정렬2

1) 어떤 전략(알고리즘)으로 해결?

  • 정렬

2) 코딩 설명

<내 풀이>


import sys
n=int(sys.stdin.readline()); lis=[]
for i in range(n) : x,y=map(int,sys.stdin.readline().rstrip().split()) ; lis.append((y,x)) ; 
lis.sort() ; 
for y,x in lis : print(x,y)

파이썬 리스트 정렬 (특정 key 기준)

https://infinitt.tistory.com/122

파이썬 람다 filter

https://coding-groot.tistory.com/21

<반성 점>

특정값 기준 sort 하기

lis.sort(key= lambda x : (x[0], -x[1]))

<배운 점>

  • list 에서 람다 써서 특정 인덱스 기준으로 정렬하게 하는거 복습하기 위해 작성
  • 그리고 미뤄뒀던 리스트 정제 방식 복습
  • 어쩌다보니 200번 문제네 그러나 어떤 간단한 문제든 늘 배우는 법이 있는 법!!

0개의 댓글