https://programmers.co.kr/learn/courses/30/lessons/72411?language=python3
코딩테스트 연습 - 메뉴 리뉴얼
레스토랑을 운영하던 스카피는 코로나19로 인한 불경기를 극복하고자 메뉴를 새로 구성하려고 고민하고 있습니다. 기존에는 단품으로만 제공하던 메뉴를 조합해서 코스요리 형태로 재구성해서
programmers.co.kr
내 풀이
다른사람의 풀이
from itertools import combinations
from collections import Counter
def solution(orders,course):
answer=[]
for i in course:
candi =[]
for menu_li in orders:
for li in combinations(menu_li,i):
res =''.join(sorted(li))
candi.append(res)
sort_candi = Counter(candi).most_common()
answer +=[menu for menu,cnt in sort_candi if cnt >1 and cnt == sort_candi[0][1]]
return sorted(answer)
이번 풀이는 막혀서 구글링을 좀 했다.
우선 이번 문제에서의 가장 큰 소득은
answer +=[menu for menu,cnt in sort_candi if cnt >1 and cnt == sort_candi[0][1]]
이 부분일거같은데
https://velog.io/@singco/Programmers-%EB%A9%94%EB%89%B4-%EB%A6%AC%EB%89%B4%EC%96%BC
Programmers - 메뉴 리뉴얼
문제링크함수와 변수이름을 정하는데 시간이 많이 든다.tuple, dictionary의 기본 api에 대해 익숙하지 않다.함수는 되도록 만들지 않는다.변수명을 지을 때 \_를 사용하자.tuple과 dictionary의 기본 api는
velog.io
자세한 설명은 참조한 블로그를 첨부한다.
'취준 > 프로그래머스' 카테고리의 다른 글
뉴스 클러스터링 - 파이썬 (0) | 2022.06.15 |
---|---|
괄호 변환 - 파이썬 (0) | 2022.06.13 |
행렬 테두리 회전하기 - 파이썬 (0) | 2022.06.06 |
짝 지어 제거하기 - 파이썬 (0) | 2022.06.02 |
더 맵게 - 파이썬 (0) | 2022.06.01 |