정렬의 우선순위에 대해 공부할 수 있는 문제다.
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
dic = dict()
note = []
for _ in range(N):
word = input().strip()
if len(word) >= M:
if word in dic:
dic[word] += 1
else:
dic[word] = 1
dic = dict(sorted(dic.items())) # 알파벳 순으로 정렬
dic = dict(sorted(dic.items(), key = lambda x : (-x[1], -len(x[0]))))
print(*dic, sep='\n')
key = lambda x : (x[1], len(x[0])), reverse=True)
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
dic = dict()
note = []
for _ in range(N):
word = input().strip()
if len(word) >= M:
if word in dic:
dic[word] += 1
else:
dic[word] = 1
dic = dict(sorted(dic.items(), key = lambda x : (-x[1], -len(x[0]), x[0])))
print(*dic, sep='\n')



오호 -를 쓴 것보다 reverse=True를 쓴 게 더 빠르다. 오름차순, 내림차순이 섞여 있을 때만 -를 써야겠다.