목차
https://www.acmicpc.net/problem/20920
20920번: 영단어 암기는 괴로워
첫째 줄에는 영어 지문에 나오는 단어의 개수 $N$과 외울 단어의 길이 기준이 되는 $M$이 공백으로 구분되어 주어진다. ($1 \leq N \leq 100\,000$, $1 \leq M \leq 10$) 둘째 줄부터 $N+1$번째 줄까지 외울 단
www.acmicpc.net
import sys
from collections import defaultdict
n,m=map(int,input().split())
dic=defaultdict(int)
for _ in range(n):
x=sys.stdin.readline().rstrip()
if len(x)>=m:
dic[x]+=1
dic2=sorted(dic.items(),key= lambda x: (-x[1],-len(x[0]),x[0]))
for x in dic2:
print(x[0])
.items과 sorted 함수를 사용해서 딕셔너리를 정렬할 수 있다.
'코딩테스트[파이썬] > 백준 (BOJ)' 카테고리의 다른 글
백준 1010 - 다리놓기[조합] (0) | 2024.02.17 |
---|---|
백준 2346 - 풍선터트리기 [큐] (0) | 2024.02.16 |
백준 12789 - 도키도키 간식드리미 (0) | 2024.02.16 |
백준 17103 - 짝[소수약수배수] (0) | 2024.02.16 |
백준 1934 - 최소공배수[유클리드 호제법] (2) | 2024.02.16 |