반응형
from itertools import combinations
from collections import Counter
def solution(orders,course):
answer = []
for k in course:
candidates = []
for menu_li in orders:
for li in combinations(menu_li,k):
res = ''.join(sorted(li))
candidates.append(res)
sorted_candidates = Counter(candidates).most_common() #개수가 많은 순으로 정렬
answer += [menu for menu, cnt in sorted_candidates if cnt > 1 and cnt == sorted_candidates[0][1]]
return sorted(answer)
반응형
'알고리즘 > 카카오 기출문제' 카테고리의 다른 글
[파이썬🐍] 프로그래머스 : [3차] 파일명 정렬 (0) | 2021.07.21 |
---|---|
[파이썬🐍] 프로그래머스 : 숫자 문자열과 영단어 (0) | 2021.07.16 |
[파이썬🐍] 프로그래머스 : [1차] 뉴스 클러스터링 (0) | 2021.06.29 |
[파이썬🐍] 프로그래머스 : 괄호 변환 (0) | 2021.06.26 |
[파이썬🐍] 프로그래머스 : [1차] 캐시 (0) | 2021.05.26 |
댓글