728x90
320x100
def solution(survey, choices):
answer = ''
table = {"R":0, "T":0, "C":0, "F":0, "J":0, "M":0, "A":0, "N":0}
for i, v in enumerate(choices):
if v == 1 or v == 2 or v == 3:
if v == 1:
table[survey[i][0]] += 3
elif v == 2:
table[survey[i][0]] += 2
elif v == 3:
table[survey[i][0]] += 1
elif v == 5 or v == 6 or v == 7:
if v == 5:
table[survey[i][1]] += 1
elif v == 6:
table[survey[i][1]] += 2
elif v == 7:
table[survey[i][1]] += 3
li = list(table.items())
for i in range(0, len(li), 2):
if li[i][1] > li[i+1][1]:
answer += li[i][0]
elif li[i][1] < li[i+1][1]:
answer += li[i+1][0]
else :
answer += li[i][0]
return answer
각 결과값을 만들긴 했는데 이걸 어떻게 비교해서 최종 결과값을 낼까 고민을 하다가
그냥 dict을 list 로 변경하신 분이 있어서 그걸 화룡해서 바로 for문 돌면서 비교 가능해서 쉽게 풀렸다 히히
728x90
320x100
'💻 하나씩 차곡차곡 > 프로그래머스 (Python)' 카테고리의 다른 글
[프로그래머스/python/Lv1] 개인정보 수집 유효기간 (0) | 2024.01.01 |
---|---|
[프로그래머스/python/Lv1] [PCCE 기출문제] 10번 / 데이터 분석 (0) | 2023.12.31 |
[프로그래머스/python/Lv1] [PCCE 기출문제] 9번 이웃한 칸 (0) | 2023.12.29 |
[프로그래머스/python/Lv1] 신규 아이디 추천 (0) | 2023.12.28 |
[프로그래머스/python/Lv1] 키패드 누르기 (0) | 2023.12.27 |