- for문을 사용하여 m길이 이상인 단어들만 words배열에 넣어줌.
- Counter의 most_common함수를 사용하여 빈도순으로 정렬된 list인 res를 return받음.
- res배열을 sort함수의 key와 lambda식을 활용하여 문제의 조건에 맞게 설정해준 후 정렬함.
import sys
from collections import Counter
def solution() :
n, m = map(int, sys.stdin.readline().split())
words = []
for _ in range(n) :
tmp = sys.stdin.readline().rstrip()
if len(tmp) >= m :
words.append(tmp)
res = Counter(words).most_common()
res.sort(key = lambda x : (-x[1], -len(x[0]), x[0]))
for r in res :
print(r[0])
solution()