https://school.programmers.co.kr/learn/courses/30/lessons/72411
from collections import defaultdict
from itertools import combinations as C
def solution(orders, course):
answer = []
for co in course:
count_dict = defaultdict(int)
for order in orders:
order = sorted(order)
for o in list(C(order, co)):
count_dict[o] += 1
ordered = dict(sorted(count_dict.items(), key=lambda x:x[1], reverse=True))
ordered_reverse = defaultdict(list)
for k, v in ordered.items():
if v >= 2:
ordered_reverse[v].append(k)
if len(ordered) != 0:
for o in ordered_reverse[max(ordered.values())]:
answer.append(o)
return [''.join(v) for v in sorted(answer)]
'Coding Test > 프로그래머스' 카테고리의 다른 글
[프로그래머스] / [Level 2] / [Python] 괄호 변환 (0) | 2023.03.27 |
---|---|
[프로그래머스] / [Level 2] / [Python] [3차] 파일명 정렬 (0) | 2023.03.27 |
[프로그래머스] / [Level 2] / [Python 오픈채팅방 (0) | 2023.03.22 |
[프로그래머스] / [Level 2] / [Python] 예상 대진표 (0) | 2023.03.20 |
[프로그래머스] / [Level 2] / [Python] k진수에서 소수 개수 구하기 (0) | 2023.03.20 |