티스토리 뷰
def solution(table, languages, preference):
answer = ''
score = []
lan_idx = 0
max_score = []
qq = []
for i in table:
score = []
for k in languages:
if k in i.split():
score.append((6 - i.split().index(k))*preference[lan_idx % len(languages)])
else:
score.append(0)
lan_idx += 1
max_score.append(sum(score))
result = max(max_score)
new_co = [i for i, ele in enumerate(max_score) if ele == result]
print(new_co)
dic = {0 :'SI',1:'CONTENTS',2:'HARDWARE',3:'PORTAL',4:'GAME'}
for i in new_co:
qq.append(dic[i])
answer = sorted(qq)[0]
return answer
-리스트는 중복된 요소를 검색하면 젤 첫번째 인덱스만 반환한다. 중복된 값이 있는 인덱스를 모두 찾기 위한 방법
new_co = [i for i, ele in enumerate(max_score) if ele == result]
-딕셔너리에서 value를 기준으로 정렬하고 싶을때 lambda이용
score_dict = {4 :'SI',9:'CONTENTS',2:'HARDWARE',3:'PORTAL',5:'GAME'}
new_dict = sorted(score_dict.items(), key=lambda x:x[1])
'알고리즘 공부 > 프로그래머스 level1' 카테고리의 다른 글
[파이썬]신규 아이디 추천 (0) | 2021.09.01 |
---|---|
[파이썬]크레인 인형뽑기 게임 (0) | 2021.09.01 |
[파이썬]숫자 문자열과 영단어 (0) | 2021.08.28 |
[파이썬] 키패드 누르기 (0) | 2021.07.29 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 스왑파일
- 프로그래머스
- 그래프
- zsh환경변수
- 플로이드워셜
- 최단경로
- 알고리즘
- arrayofodject #배열객체저장 #firestore #nestedaraay
- 최단거리
- vi비정상 종료
- 다익스트라
- 코딩테스트
- 코테
- zsh
- 파이썬
- E325: ATTENTIONFound
- zsh compinit: insecure directories
- zsh 에러
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함