문제풀이/프로그래머스

[프로그래머스] - 성격 유형 검사하기

얄루몬 2023. 4. 8. 12:40

python

def solution(survey, choices):
    answer = ''
    dic= {"R" : 0,"T" : 0,"C" : 0,"F" : 0,"J" : 0,"M" : 0,"A" : 0,"N" : 0 }

    
    #4의 경우엔 점수 부여하지 않으니까 4를 기준으로 나눠주면 된다.
    for s,c in zip(survey, choices):
        if c > 4: 
            dic[s[1]] += c-4
        elif c < 4:
            dic[s[0]] += 4-c
            
    li = list(dic.items())

    for i in range(0,8,2):
        if li[i][1] < li[i+1][1]:
            answer += li[i+1][0]
        else:
            answer += li[i][0]
        
        
    return answer
  • 해당 딕셔너리를 list로 다시 변환시켜서 해당 값들을 비교해주면 된다.