코딩 테스트 준비

영단어 암기는 괴로워 - 실버3 (백준, 문자열)

개발쉐발 2023. 1. 18. 15:41
728x90
반응형
import sys

input = sys.stdin.readline
N, M = map(int,input().split())
voca = []
dict = {}
for _ in range(N):
  word = input()
  word = word[:-1]
  if len(word) >= M:
    voca.append(word)
    dict[word] = 0
    
for i in voca:
  dict[i] += 1
  
ans = sorted(dict.items(), key=lambda x: (-x[1], -len(x[0]), x[0]))

for i in ans:
  print(i[0])

 

잊지 말아야할 포인트는 sorted나 sort를 할때 특정 조건을 오름차순으로 하고 싶으면 -를 붙이면 된다는 것.

728x90
반응형