Counter
, most_common()
)-
)import sys
from collections import Counter
input = sys.stdin.readline
N, M = map(int, input().rstrip().split())
arr = []
for _ in range(N):
arr.append(input().rstrip())
words = [word for word in arr if len(word) >= M]
res = Counter(words).most_common()
# print(f'words: {words}')
# print(f'res: {res}')
res.sort(key=lambda x: (-x[1], -len(x[0]), x[0]))
# print(f'res - after sort: {res}')
for i in res:
print(i[0])
▶️ 최빈값 기준으로 정렬하기(Counter
, most_common()
)
▶️ 정렬 기준 값 잘 사용(내림차순 정렬 조건을 추가할 때 : -
)